Example #1
0
 static function createModuleMetaFile()
 {
     $adb = PearDatabase::getInstance();
     $sql = "select * from vtiger_tab";
     $result = $adb->pquery($sql, array());
     $num_rows = $adb->num_rows($result);
     $result_array = array();
     $seq_array = array();
     $ownedby_array = array();
     for ($i = 0; $i < $num_rows; $i++) {
         $tabid = $adb->query_result($result, $i, 'tabid');
         $tabname = $adb->query_result($result, $i, 'name');
         $presence = $adb->query_result($result, $i, 'presence');
         $ownedby = $adb->query_result($result, $i, 'ownedby');
         $result_array[$tabname] = $tabid;
         $seq_array[$tabid] = $presence;
         $ownedby_array[$tabid] = $ownedby;
     }
     //Constructing the actionname=>actionid array
     $actionid_array = array();
     $sql1 = "select * from vtiger_actionmapping";
     $result1 = $adb->pquery($sql1, array());
     $num_seq1 = $adb->num_rows($result1);
     for ($i = 0; $i < $num_seq1; $i++) {
         $actionname = $adb->query_result($result1, $i, 'actionname');
         $actionid = $adb->query_result($result1, $i, 'actionid');
         $actionid_array[$actionname] = $actionid;
     }
     //Constructing the actionid=>actionname array with securitycheck=0
     $actionname_array = array();
     $sql2 = "select * from vtiger_actionmapping where securitycheck=0";
     $result2 = $adb->pquery($sql2, array());
     $num_seq2 = $adb->num_rows($result2);
     for ($i = 0; $i < $num_seq2; $i++) {
         $actionname = $adb->query_result($result2, $i, 'actionname');
         $actionid = $adb->query_result($result2, $i, 'actionid');
         $actionname_array[$actionid] = $actionname;
     }
     $filename = 'user_privileges/tabdata.php';
     if (file_exists($filename)) {
         if (is_writable($filename)) {
             if (!($handle = fopen($filename, 'w+'))) {
                 echo "Cannot open file ({$filename})";
                 exit;
             }
             require_once 'modules/Users/CreateUserPrivilegeFile.php';
             $newbuf = '';
             $newbuf .= "<?php\n\n";
             $newbuf .= "\n";
             $newbuf .= "//This file contains the commonly used variables \n";
             $newbuf .= "\n";
             $newbuf .= "\$tab_info_array=" . constructArray($result_array) . ";\n";
             $newbuf .= "\n";
             $newbuf .= "\$tab_seq_array=" . constructArray($seq_array) . ";\n";
             $newbuf .= "\n";
             $newbuf .= "\$tab_ownedby_array=" . constructArray($ownedby_array) . ";\n";
             $newbuf .= "\n";
             $newbuf .= "\$action_id_array=" . constructSingleStringKeyAndValueArray($actionid_array) . ";\n";
             $newbuf .= "\n";
             $newbuf .= "\$action_name_array=" . constructSingleStringValueArray($actionname_array) . ";\n";
             $newbuf .= "?>";
             fputs($handle, $newbuf);
             fclose($handle);
         } else {
             echo "The file {$filename} is not writable";
         }
     } else {
         echo "The file {$filename} does not exist";
     }
 }
/**
 * Function to write the tabid and name to a flat file vtiger_tabdata.txt so that the data
 * is obtained from the file instead of repeated queries
 * returns null
 */
function create_tab_data_file()
{
    global $log;
    $log->debug("Entering create_tab_data_file() method ...");
    $log->info("creating vtiger_tabdata file");
    global $adb;
    //$sql = "select * from vtiger_tab";
    // vtlib customization: Disabling the tab item based on presence
    $sql = "select * from vtiger_tab where presence in (0,2)";
    // END
    $result = $adb->pquery($sql, array());
    $num_rows = $adb->num_rows($result);
    $result_array = array();
    $seq_array = array();
    $ownedby_array = array();
    for ($i = 0; $i < $num_rows; $i++) {
        $tabid = $adb->query_result($result, $i, 'tabid');
        $tabname = $adb->query_result($result, $i, 'name');
        $presence = $adb->query_result($result, $i, 'presence');
        $ownedby = $adb->query_result($result, $i, 'ownedby');
        $result_array[$tabname] = $tabid;
        $seq_array[$tabid] = $presence;
        $ownedby_array[$tabid] = $ownedby;
    }
    //Constructing the actionname=>actionid array
    $actionid_array = array();
    $sql1 = "select * from vtiger_actionmapping";
    $result1 = $adb->pquery($sql1, array());
    $num_seq1 = $adb->num_rows($result1);
    for ($i = 0; $i < $num_seq1; $i++) {
        $actionname = $adb->query_result($result1, $i, 'actionname');
        $actionid = $adb->query_result($result1, $i, 'actionid');
        $actionid_array[$actionname] = $actionid;
    }
    //Constructing the actionid=>actionname array with securitycheck=0
    $actionname_array = array();
    $sql2 = "select * from vtiger_actionmapping where securitycheck=0";
    $result2 = $adb->pquery($sql2, array());
    $num_seq2 = $adb->num_rows($result2);
    for ($i = 0; $i < $num_seq2; $i++) {
        $actionname = $adb->query_result($result2, $i, 'actionname');
        $actionid = $adb->query_result($result2, $i, 'actionid');
        $actionname_array[$actionid] = $actionname;
    }
    $filename = 'tabdata.php';
    if (file_exists($filename)) {
        if (is_writable($filename)) {
            if (!($handle = fopen($filename, 'w+'))) {
                echo "Cannot open file ({$filename})";
                exit;
            }
            require_once 'modules/Users/CreateUserPrivilegeFile.php';
            $newbuf = '';
            $newbuf .= "<?php\n\n";
            $newbuf .= "\n";
            $newbuf .= "//This file contains the commonly used variables \n";
            $newbuf .= "\n";
            $newbuf .= "\$tab_info_array=" . constructArray($result_array) . ";\n";
            $newbuf .= "\n";
            $newbuf .= "\$tab_seq_array=" . constructArray($seq_array) . ";\n";
            $newbuf .= "\n";
            $newbuf .= "\$tab_ownedby_array=" . constructArray($ownedby_array) . ";\n";
            $newbuf .= "\n";
            $newbuf .= "\$action_id_array=" . constructSingleStringKeyAndValueArray($actionid_array) . ";\n";
            $newbuf .= "\n";
            $newbuf .= "\$action_name_array=" . constructSingleStringValueArray($actionname_array) . ";\n";
            $newbuf .= "?>";
            fputs($handle, $newbuf);
            fclose($handle);
        } else {
            echo "The file {$filename} is not writable";
        }
    } else {
        echo "The file {$filename} does not exist";
        $log->debug("Exiting create_tab_data_file method ...");
        return;
    }
}