<?php
require_once('Common.php');
require_once(
'../shared/php/mate/php/lang/LangVars-en.php');
require_once(
'../shared/php/mate/php/AjaxTableEditor.php');
class 
Example2 extends Common
{

    var 
$loginTable;
    var 
$empTable;

    function 
updateLogin($empId)
    {
        
$query "select first_name, last_name from $this->empTable where id = '$empId'";
        
$result $this->doQuery($query);
        if(
$row mysql_fetch_array($result,MYSQL_ASSOC))
        {
            
$suggestedLogin strtolower(substr($row['first_name'],0,1).$row['last_name']).rand(100,999);
            
$this->Editor->retArr[] = array('where' => 'javascript''value' => '$("login").value = "'.$suggestedLogin.'";');
        }
    }

    function 
displayHtml()
    {
        
?>

        <!-- start content -->
        <div id="content">
            <div class="flower"></div>
            <div class="post">
                <h1 class="title title-big">Join Demo</h1>
                <div class="entry">

                <p>This demo joins the employee table seen in the <a href="Example1.php">first demo</a>.</p>
                <p>This page has an example of a dynamic form. Check out the add and edit screens to see how the login value changes when an employee is selected.</p>
                <p>Also when a new employee is added to the employee table (in the first demo), he/she will automatically show up in the add and edit screens of this table.</p>
                
                <div><a target="_blank" href="ShowSourceCode.php?file_name=Example2.php">Configuration File Source</a></div>
                <div><a target="_blank" href="ShowTableData.php?table_name=<?=$this->loginTable?>">Raw Table Data</a></div>        
                
                <div align="left" style="position: relative;"><div id="ajaxLoader1"><img src="http://www.marketingemailautomator.com/shared/images/ajax_loader.gif" alt="Loading..." /></div></div>
                <br />
                <div id="historyButtonsLayer" align="left">
                </div>
        
                <div id="historyContainer">
                    <div id="information">
                    </div>
            
                    <div id="titleLayer" style="padding: 2px; font-weight: bold; font-size: 18px; text-align: center;">
                    </div>
            
                    <div id="tableLayer" align="center">
                    </div>
                    
                    <div id="recordLayer" align="center">
                    </div>        
                    
                    <div id="searchButtonsLayer" align="center">
                    </div>
                </div>
            </div>
            <br /><br /><br />
        </div>
        <!-- end content -->
    
        <br clear="left" />

        <script type="text/javascript">
            trackHistory = true;
            var ajaxUrl = '<?php echo $_SERVER['PHP_SELF']; ?>';
            toAjaxTableEditor('update_html','');
        </script>
        <?php
    
}

    function 
initiateEditor()
    {
        
$tableColumns['id'] = array('display_text' => 'ID''perms' => '');
        
$tableColumns['employee_id'] = array('display_text' => 'Name''perms' => 'EVCTAXQ''join' => array('table' => $this->empTable'column' => 'id''display_mask' => "concat($this->empTable.first_name,' ',$this->empTable.last_name)"'type' => 'left'),'input_info' => 'onchange="toAjaxTableEditor(\'update_login\',this.value);"');
        
$tableColumns['login'] = array('display_text' => 'Login''perms' => 'EVCTAXQ');
        
$tableColumns['password'] = array('display_text' => 'Password''perms' => 'EVCAXQT','mysql_add_fun' => 'PASSWORD','mysql_edit_fun' => 'PASSWORD'); 
        
$tableColumns['account_type'] = array('display_text' => 'Account Type''perms' => 'EVCTAXQ''select_array' => array('Admin' => 'Admin''User' => 'User'), 'default' => 'User'); 
        
        
$table $this->loginTable;
        
$primaryCol 'id';
        
$errorFun = array(&$this,'logError');
        
$permissions 'EAVDQCSM';
        
        
$this->Editor = new AjaxTableEditor($table,$primaryCol,$errorFun,$permissions,$tableColumns);
        
$this->Editor->setConfig('tableInfo','cellpadding="1" width="900" class="mateTable"');
        
$this->Editor->setConfig('orderByColumn','employee_id');
        
$this->Editor->setConfig('tableTitle','Login Info');
        
$this->Editor->setConfig('addRowTitle','Add Login Info');
        
$this->Editor->setConfig('editRowTitle','Edit Login Info');
        
$this->Editor->setConfig('viewRowTitle','View Login Info');
        
$userActions = array('update_login' => array(&$this,'updateLogin'));
        
$this->Editor->setConfig('userActions',$userActions);
        
$this->Editor->setConfig('tableTitle','Employee Login Info');
    }
    
    
    function 
Example2()
    {
        
$this->mysqlConnect();
        
$this->startSession();
        
$this->setTableNames();
        
$this->checkForTables();
        if(isset(
$_POST['json']))
        {
            if(
ini_get('magic_quotes_gpc'))
            {
                
$_POST['json'] = stripslashes($_POST['json']);
            }
            if(
function_exists('json_decode'))
            {
                
$data json_decode($_POST['json']);
            }
            else
            {
                require_once(
'php/JSON.php');
                
$js = new Services_JSON();
                
$data $js->decode($_POST['json']);
            }
            if(empty(
$data->info) && strlen(trim($data->info)) == 0)
            {
                
$data->info '';
            }
            
$this->initiateEditor();
            
$this->Editor->main($data->action,$data->info);
            if(
function_exists('json_encode'))
            {
                echo 
json_encode($this->Editor->retArr);
            }
            else
            {
                echo 
$js->encode($this->Editor->retArr);
            }
        }
        else if(isset(
$_GET['export']))
        {
            
$this->initiateEditor();
            echo 
$this->Editor->exportInfo();
            
header("Cache-Control: no-cache, must-revalidate");
            
header("Pragma: no-cache");
            
header("Content-type: application/x-msexcel");            
            
header('Content-Type: text/csv');
            
header('Content-Disposition: attachment; filename="login_info.csv"');
            exit();
        }
        else
        {
            
$this->dispAds false;
            
$this->displayHeaderHtml();
            
$this->displayHtml();
            
$this->displayFooterHtml();
        }
    }
}
$lte = new Example2();
?>
1