Exemplo n.º 1
0
function handleSearchPage()
{
    include_once 'login.php';
    include_once 'database_conn.php';
    include_once 'showEventFunction.php';
    $pageHeader = "Result";
    $output = "<h1>{$pageHeader}</h1>";
    $backURL = "<br/><a href = \"searchPage.php\">Back</a>\n\t<br/><a href = \"index.php\">Back to Home</a>\n\t";
    $event = array();
    foreach ($_POST as $field => $value) {
        //echo "$field => $value <br/>";
        if (strcmp($field, "submit") === 0) {
            continue;
        }
        $event[$field] = $value;
        // sanitizeData($value);
    }
    $event = array_filter($event);
    //if any field is not filled, stop user
    //then ask user to enter something
    if (empty($event)) {
        $output .= "Please describe something to search.";
        return $output . $backURL;
    }
    $sql = generateSQL($event);
    $datas = array();
    $datas['venues'] = getFromDb($conn, "SELECT * FROM te_venue");
    $datas['categories'] = getFromDb($conn, "SELECT * FROM te_category");
    $datas['events'] = getFromDb($conn, $sql);
    $datas['events'] = array_filter($datas['events']);
    // if there is record, show in table
    if (!empty($datas['events'])) {
        $output .= showTable($datas, false);
        return $output . $backURL;
    } else {
        //if there is no result, result not found
        $output .= "No record found.";
        return $output . $backURL;
    }
}
Exemplo n.º 2
0
        $sqlstmt = $sqlstmt . ' (' . $sqlstmtVars . ') VALUES (' . $sqlstmtValues . ')";' . LB;
    }
    return $sqlstmt;
}
if (count($exportforms) > 0) {
    // Create an array for all fieldnames and their values for this record.
    $date = COM_getUserDateTimeFormat();
    $exportscript .= '<?php' . LB;
    $exportscript .= '// Export Form Defintion for: ' . DB_getItem($_TABLES['nxform_definitions'], 'name', "id='{$formid}'") . LB;
    $exportscript .= '// Date: ' . $date[0] . LB . LB;
    $i = 1;
    foreach ($exportforms as $formid) {
        $exportscript .= LB . LB . '# Export Form Definitions ' . LB;
        $exportscript .= generateSQL('formDefinitions', $formid, "900{$i}");
        $exportscript .= LB . '# Export Field Definitions ' . LB;
        $exportscript .= generateSQL('formFields', $formid, "900{$i}");
        $i++;
    }
    $exportscript .= LB . '?>';
    if (!($fp = @fopen($downloadDirectory . $file, "w"))) {
        COM_errorLog("Error exporting form definition - Unable to write to file: {$exportfile}");
    } else {
        fwrite($fp, $exportscript);
        fclose($fp);
        // Send new file to user's browser
        $download = new downloader();
        $download->_setAvailableExtensions($downloadFileType);
        $download->setAllowedExtensions($downloadFileType);
        $download->setPath($downloadDirectory);
        $logfile = $_CONF['path'] . 'logs/error.log';
        $download->setLogFile($logfile);
Exemplo n.º 3
0
 public function setNode($node, $force = FALSE, $action = "SaveNode")
 {
     global $system;
     global $ignoreValidationErrors;
     global $trackNodeContext;
     $execute = TRUE;
     $next = array();
     $new = FALSE;
     $isDelta = FALSE;
     $deltaReport = array();
     $reviewState = 0;
     if (isset($node["node"]["Node_id"]) && $node["node"]["Node_id"] !== FALSE && isset($node["node"]["Parent_id"]) && isset($node["node"]["Type"])) {
         if (isset($node["Errors"])) {
             unset($node["Errors"]);
         }
         $nodeId = $node["node"]["Node_id"];
         $nodeType = $node["node"]["Type"];
         $nodeType2 = $node["node"]["Type"];
         $nodeParent = $node["node"]["Parent_id"];
         if (isset($node["node"]["Review"])) {
             $nodeReview = $node["node"]["Review"];
         } else {
             $nodeReview = 0;
         }
         if (isset($node["node"]["Review_member"])) {
             $nodeReviewMember = $node["node"]["Review_member"];
         } else {
             $nodeReviewMember = 0;
         }
         $controlInfo = getNodeContext($nodeId, FALSE, TRUE);
         if (!$controlInfo) {
             $new = TRUE;
         }
         // print_r($controlInfo);
         if ($node["node"]["Node_id"] == 0) {
             $new = TRUE;
             $next = getNextFreeIds("mt_main", $system["Offset"], FALSE, 0);
             $node["node"]["Node_id"] = $next[0];
             $nodeId = $next[0];
         }
         if ($new) {
             $isDelta = TRUE;
             $controlInfo = array();
             $controlInfo["node"] = array("Node_id" => $nodeId, "Parent_id" => $nodeParent, "Title" => "", "Image" => "", "Type" => $nodeType, "Protected" => 0, "Review" => 0, "Review_member" => 0, "Update" => 0);
             $controlInfo["data"] = array("Review" => 0, "Rights" => "", "Dependancies" => "", "Values" => array());
             $controlInfo["rights"] = array();
             $attributes = array();
             $attributesKeys = array();
             if (isset($system["Types"][$nodeType2]["__Fields__"])) {
                 $typeAttributes = $system["Types"][$nodeType2]["__Fields__"];
             } else {
                 $typeAttributes = array();
             }
             $attributesMultiLang = array();
             $attributesNames = array();
             $keys_typeAtt = array_keys($typeAttributes);
             for ($i = 0; $i < count($keys_typeAtt); $i++) {
                 $cf = $typeAttributes[$keys_typeAtt[$i]];
                 $value = "";
                 $attributesKey = $cf["__Name__"];
                 $attributesKeys[] = $attributesKey;
                 $attributesNames[$cf["__Name__"]] = "";
                 $attributes[$attributesKey] = $cf;
                 if ($cf["Monolingual"] == 0) {
                     $attributesMultiLang[$attributesKey] = "";
                 }
                 echo $fieldId = $keys_typeAtt[$i];
                 $fieldType = $cf["BaseType"];
                 $fieldName = $cf["__Name__"];
                 $keys = array_keys($system["Languages"]);
                 for ($j = 0; $j < count($keys); $j++) {
                     $language = translateIds2old("Languages", $keys[$j]);
                     if (!isset($node["data"]["Values"][$language][$attributesKey])) {
                         $node["data"]["Values"][$language][$attributesKey] = "";
                     } else {
                         $controlInfo["data"]["Values"][$language][$attributesKey] = "";
                     }
                 }
             }
         }
         // print_r($controlInfo);
         if (!isset($controlInfo["rights"])) {
             $controlInfo["rights"] = array();
         }
         if (!isset($node["node"]["Position"])) {
             $node["node"]["Position"] = 0;
         }
         if (!isset($node["node"]["Protected"])) {
             $node["node"]["Protected"] = 0;
         }
         if (!isset($node["node"]["Review"])) {
             $node["node"]["Review"] = 0;
         }
         if (!isset($node["node"]["Review_member"])) {
             $node["node"]["Review_member"] = 0;
         }
         if (!isset($node["node"]["Image"])) {
             $node["node"]["Image"] = $system["Types"][$nodeType2]["__Icon__"];
         }
         $node["node"]["Update"] = date("YmdHis");
         // #################### Workflow ####################
         if ($nodeReviewMember != 0 && $node["node"]["Review_member"] != $controlInfo["node"]["Review_member"]) {
             // echo "bad way to change RMember...";
             $node["node"]["Review_member"] = $controlInfo["node"]["Review_member"];
         }
         if ($nodeReviewMember != 0) {
             if (isset($node["node"]["NewReview_member"]) && isset($node["node"]["Review_Comment"])) {
                 $member = getReviewMemberInfo($nodeReviewMember);
                 $oldReviewMemberId = $node["node"]["Review_member"];
                 $reviewMemberId = $node["node"]["NewReview_member"];
                 if ($oldReviewMemberId != $reviewMemberId) {
                     $node["node"]["Review_member"] = $reviewMemberId;
                     if (isset($member["mt_review_levels_Change_Action"]) && trim($member["mt_review_levels_Change_Action"] != "")) {
                         eval("?" . ">" . $member["mt_review_levels_Change_Action"]);
                     }
                     if (isset($member["mt_review_members_Change_Action"]) && trim($member["mt_review_members_Change_Action"] != "")) {
                         eval("?" . ">" . $member["mt_review_members_Change_Action"]);
                     }
                     $actor = getNodeContext($_SESSION["User"]["User_id"]);
                     $newState = getReviewMemberInfo($reviewMemberId);
                     if ($newState["mt_review_members_User_id"] != 0) {
                         $user = getNodeContext($newState["mt_review_members_User_id"]);
                     } else {
                         $user["node"] = array("Node_id" => 0, "Title" => "Open User Definition");
                     }
                     $fileStream = date("YmdHis") . ";";
                     $fileStream .= $member["mt_review_levels_Name"] . ";";
                     $fileStream .= $actor["node"]["Node_id"] . ";";
                     $fileStream .= str_replace(";", ",", $actor["node"]["Title"]) . ";";
                     $fileStream .= $oldReviewMemberId . ";";
                     $fileStream .= $reviewMemberId . ";";
                     $fileStream .= $user["node"]["Node_id"] . ";";
                     $fileStream .= str_replace(";", ",", $user["node"]["Title"]) . ";";
                     $fileStream .= serialize($node["node"]["Review_Comment"]) . "\r\n";
                     $fileName = $system["systemFilePath"] . "log/" . $node["node"]["Node_id"] . "_review.log";
                     appendLogFile($fileName, $fileStream);
                 }
                 $nodeReviewMember = $reviewMemberId;
             }
             $member = getReviewMemberInfo($nodeReviewMember);
             if (isset($member["mt_review_levels_Position"]) && $member["mt_review_levels_Position"] > 10) {
                 $reviewState = 1;
             } else {
                 $reviewState = 0;
             }
             $node["node"]["Review"] = $reviewState;
             $node["data"]["Review"] = $reviewState;
         }
         // ################## Extra Code ####################
         if ($execute) {
             if ($new) {
                 if (trim($system["Types"][$nodeType2]["Creation_Code"])) {
                     eval("?" . ">" . $system["Types"][$nodeType2]["Creation_Code"]);
                 }
             } else {
                 if ($node["node"]["Parent_id"] == 3) {
                     if (trim($system["Types"][$nodeType2]["Erase_Code"])) {
                         eval("?" . ">" . $system["Types"][$nodeType2]["Erase_Code"]);
                     }
                     findLinks($node["node"]["Node_id"], $execute);
                 } else {
                     if (trim($system["Types"][$nodeType2]["Save_Code"])) {
                         eval("?" . ">" . $system["Types"][$nodeType2]["Save_Code"]);
                     }
                 }
             }
         }
         // ##################################################
         $DBArray = array();
         $DBArray["table"] = "mt_main";
         $DBArray["master"]["mt_main_Node_id"] = $nodeId;
         $DBArray["master"]["mt_main_Review"] = $reviewState;
         $DBArray["data"]["mt_main_Parent_id"] = $nodeParent;
         $DBArray["data"]["mt_main_Title"] = $node["node"]["Title"];
         $DBArray["data"]["mt_main_Image"] = $node["node"]["Image"];
         $DBArray["data"]["mt_main_Type"] = $nodeType;
         $DBArray["data"]["mt_main_Position"] = $node["node"]["Position"];
         $DBArray["data"]["mt_main_Protected"] = $node["node"]["Protected"];
         $DBArray["data"]["mt_main_Review_member"] = $node["node"]["Review_member"];
         $DBArray["data"]["mt_main_Update"] = $node["node"]["Update"];
         $nodeQuery = generateSQL($DBArray);
         // ##################################################
         if (!isset($node["node"])) {
             $node["node"] = array();
         }
         if (!isset($controlInfo["node"])) {
             $controlInfo["node"] = array();
         }
         $diff = array_diff_assoc($controlInfo["node"], $node["node"]);
         if (isset($diff["Update"])) {
             unset($diff["Update"]);
         }
         if (count($diff)) {
             $deltaReport["node"] = $diff;
         }
         // ##################################################
         if (!isset($node["data"]) || !is_array($node["data"])) {
             $node["data"] = array();
         }
         if (!isset($node["data"]["Review"])) {
             $node["data"]["Review"] = $reviewState;
         }
         if (!isset($node["data"]["Rights"])) {
             $node["data"]["Rights"] = array();
         }
         if (!isset($node["data"]["Dependancies"])) {
             $node["data"]["Dependancies"] = "";
         }
         if (!isset($node["data"]["Values"])) {
             $node["data"]["Values"] = array();
         }
         if (!is_array($controlInfo["data"]["Rights"])) {
             $controlInfo["data"]["Rights"] = array();
         }
         if (!is_array($node["data"]["Rights"])) {
             $node["data"]["Rights"] = array();
         }
         if (!isset($controlInfo["rights"]) || !is_array($controlInfo["rights"])) {
             $controlInfo["rights"] = array();
         }
         if (!isset($node["rights"]) || !is_array($node["rights"])) {
             $node["rights"] = array();
         }
         $DeltaArray = array();
         if (!isset($controlInfo["data"])) {
             $controlInfo["data"] = array();
         }
         $diff = array_diff_assoc($controlInfo["data"], $node["data"]);
         if (count($diff)) {
             $deltaReport["data"] = $diff;
             $isDelta = TRUE;
         }
         $keys = array_keys($system["Languages"]);
         for ($i = 0; $i < count($keys); $i++) {
             $Lang_id = translateIds2old("Languages", $keys[$i]);
             $Delta = array();
             if (isset($node["data"]["Values"][$Lang_id])) {
                 // ["data"]["Values"][$Lang_id]
                 if (!isset($controlInfo["data"]["Values"][$Lang_id])) {
                     $controlInfo["data"]["Values"][$Lang_id] = array();
                 }
                 $diff = array_diff_assoc($controlInfo["data"]["Values"][$Lang_id], $node["data"]["Values"][$Lang_id]);
                 if (count($diff)) {
                     $deltaReport["data"]["Values"][$Lang_id] = $diff;
                     $isDelta = TRUE;
                 }
                 $Delta = array_merge($controlInfo["data"]["Values"][$Lang_id], $node["data"]["Values"][$Lang_id]);
                 $DeltaArray[$Lang_id] = $Delta;
             }
         }
         $nodeInfo = $node;
         // echo "<pre>";
         // print_r($system["Types"][$nodeType2]);
         // Workaround until complete change of rights
         $rightsData = FALSE;
         if (isset($node["rights"]) && is_array($node["rights"])) {
             $diff = array_diff_assoc($node["rights"], $controlInfo["rights"]);
             if (count($diff)) {
                 if (isset($node["data"]["Rights"])) {
                     $diff = array_diff_assoc($node["data"]["Rights"], $controlInfo["data"]["Rights"]);
                     if (!count($diff)) {
                         $node["data"]["Rights"] = $node["rights"];
                     }
                 }
             }
         }
         if (isset($node["data"]["Rights"])) {
             $diff = array_diff_assoc($node["data"]["Rights"], $controlInfo["data"]["Rights"]);
             if (count($diff)) {
                 $isDelta = TRUE;
                 $right = array_merge($controlInfo["data"]["Rights"], $node["data"]["Rights"]);
                 $empty = array();
                 if (version_compare(phpversion(), "5.0.1") >= 0) {
                     $empty = array_keys($node["data"]["Rights"], "", TRUE);
                 } else {
                     $empty = array_keys($node["data"]["Rights"], "");
                 }
                 for ($i = 0; $i < count($empty); $i++) {
                     if (isset($node["data"]["Rights"][$empty[$i]])) {
                         unset($node["data"]["Rights"][$empty[$i]]);
                     }
                 }
                 $deltaReport["data"]["Rights"] = $node["data"]["Rights"];
             }
         }
         if ($isDelta || $ignoreValidationErrors) {
             $attributes = array();
             $attributesKeys = array();
             $typeAttributes = array();
             if (isset($system["Types"][$nodeType2]["__Fields__"])) {
                 $typeAttributes = $system["Types"][$nodeType2]["__Fields__"];
             }
             $attributesMultiLang = array();
             $attributesNames = array();
             $keys_typeAtt = array_keys($typeAttributes);
             for ($i = 0; $i < count($keys_typeAtt); $i++) {
                 $cf = $typeAttributes[$keys_typeAtt[$i]];
                 $cf["Unique"] = $keys_typeAtt[$i];
                 $attributesKey = $cf["__Name__"];
                 $attributesKeys[] = $attributesKey;
                 $attributesNames[$cf["__Name__"]] = "";
                 $attributes[$attributesKey] = $cf;
                 if (isset($cf["Monolingual"]) && $cf["Monolingual"] == 0) {
                     $attributesMultiLang[$attributesKey] = "";
                 }
             }
             $Data = array();
             if (!isset($controlInfo["data"]) || !isset($controlInfo["data"]["Values"]) || !isset($controlInfo["data"]["Values"][1])) {
                 $controlInfo["data"]["Values"][1] = array();
             }
             if (!isset($DeltaArray[1])) {
                 $DeltaArray[1] = array();
             }
             $MainData = array_merge($attributesNames, $controlInfo["data"]["Values"][1], $DeltaArray[1]);
             $keys = array_keys($system["Languages"]);
             for ($j = 0; $j < count($keys); $j++) {
                 $language = translateIds2old("Languages", $keys[$j]);
                 for ($i = 0; $i < count($attributesKeys); $i++) {
                     $cf = $attributes[$attributesKeys[$i]];
                     $value = FALSE;
                     $nodeInfo = $node;
                     $fieldId = $cf["Unique"];
                     $fieldId = $attributes[$attributesKeys[$i]]["Id"];
                     // ALTLAST
                     $fieldName = $attributes[$attributesKeys[$i]]["__Name__"];
                     $fieldType = $attributes[$attributesKeys[$i]]["BaseType"];
                     if ($cf["Monolingual"] == 1) {
                         $fieldLanguage = 1;
                     } else {
                         $fieldLanguage = $language;
                     }
                     if ($fieldLanguage == 1) {
                         if ($fieldLanguage == $language) {
                             $value = $MainData[$attributesKeys[$i]];
                         }
                     } else {
                         if (isset($DeltaArray[$language][$attributesKeys[$i]])) {
                             $value = $DeltaArray[$language][$attributesKeys[$i]];
                         }
                     }
                     if ($value !== FALSE) {
                         $Data[$language][$fieldId] = $value;
                     }
                 }
             }
             $DBArray = array();
             $DBArray["table"] = "mt_data";
             $DBArray["master"]["mt_data_Node_id"] = $node["node"]["Node_id"];
             $DBArray["master"]["mt_data_Review"] = $reviewState;
             $DBArray["data"]["mt_data_Type"] = $nodeType;
             $DBArray["data"]["mt_data_Dependencies"] = " " . trim($node["data"]["Dependancies"]) . " ";
             if (count($node["data"]["Rights"])) {
                 $DBArray["data"]["mt_data_Rights"] = serialize($node["data"]["Rights"]);
             } else {
                 $DBArray["data"]["mt_data_Rights"] = "";
             }
             if (count($Data)) {
                 $DBArray["data"]["mt_data_Value"] = serialize($Data);
             } else {
                 $DBArray["data"]["mt_data_Value"] = "";
             }
             $dataQuery = generateSQL($DBArray);
         }
         // print_r($node);
         if ($node["node"]["Parent_id"] == 3 && isset($node["Errors"])) {
             unset($node["Errors"]);
         }
         // ##################################################
         if ((!isset($node["Errors"]) || $ignoreValidationErrors && isset($node["Errors"]) || $new || $force) && $reviewState != -1) {
             if ($execute) {
                 if (isset($nodeQuery)) {
                     mysql_query($nodeQuery, $system["dbCon"]);
                 }
                 if (isset($dataQuery)) {
                     mysql_query($dataQuery, $system["dbCon"]);
                 }
                 // if(isset($rightQuery)) mysql_query($rightQuery,$system["dbCon"]);
                 if ($trackNodeContext && count($deltaReport) && isset($_SESSION["User"]["User_id"]) && $_SESSION["User"]["User_id"]) {
                     $u = getNodeContext($_SESSION["User"]["User_id"]);
                     $fileStream = date("YmdHis") . ";" . str_replace(";", ",", $action) . ";";
                     $fileStream .= $u["node"]["Node_id"] . ";" . str_replace(";", ",", $u["node"]["Title"]) . ";";
                     $fileStream .= str_replace("\r", "\\r", str_replace("\n", "\\n", serialize($deltaReport))) . "\r\n";
                     $fileName = $system["systemFilePath"] . "log/" . $node["node"]["Node_id"] . ".txt";
                     appendLogFile($fileName, $fileStream);
                 }
                 // if(isset($system["Types"][$nodeType2]["Save_Code"]) && trim($system["Types"][$nodeType2]["Save_Code"])!="") {
                 // $reason = FALSE;
                 // eval("?".">".$system["Types"][$nodeType2]["Save_Code"]);
                 // if($reason!==FALSE) $node["Errors"][$fieldName] = $reason;
                 // }
                 if ($reviewState === 0) {
                     $dbQuery = "DELETE FROM mt_main WHERE mt_main_Node_id='" . $node["node"]["Node_id"] . "' AND mt_main_Review='1';";
                     mysql_query($dbQuery, $system["dbCon"]);
                     $dbQuery = "DELETE FROM mt_data WHERE mt_data_Node_id='" . $node["node"]["Node_id"] . "' AND mt_data_Review='1';";
                     mysql_query($dbQuery, $system["dbCon"]);
                 }
             } else {
                 echo "<pre>";
                 print_r($deltaReport);
                 echo "</pre>";
                 if (isset($nodeQuery)) {
                     echo $nodeQuery . "<br/>";
                 }
                 if (isset($dataQuery)) {
                     echo $dataQuery . "<br/>";
                 }
                 if ($reviewState === 0) {
                     $dbQuery = "DELETE FROM mt_main WHERE mt_main_Node_id='" . $node["node"]["Node_id"] . "' AND mt_main_Review='1';";
                     echo $dbQuery . "<br/>";
                     $dbQuery = "DELETE FROM mt_data WHERE mt_data_Node_id='" . $node["node"]["Node_id"] . "' AND mt_data_Review='1';";
                     echo $dbQuery . "<br/>";
                 }
             }
         }
         // ##################################################
     } else {
         $node = FALSE;
     }
     // ##################################################
     // Workaround until complete change of rights
     // $node["rights"] = $node["data"]["Rights"];
     unset($node["rights"]);
     // ##################################################
     return $node;
 }
     printUpdateStatus('OK');
 }
 //end foreach
 /**
  * Go through each table,
  * grab the data from the source table
  * and put it in the destination table.
  */
 foreach ($info['tables'] as $tablename => $table_info) {
     if ($tablename === 'sch_idx') {
         pre_echo('Skipping search table - you will need to re-index');
         continue;
     }
     pre_echo('Starting table: sq_' . $tablename);
     $columns = array_keys($table_info['columns']);
     $sql = generateSQL($tablename, $columns);
     /**
      * Switch to the source db connector to get the data..
      */
     MatrixDAL::changeDb($source_db);
     if (!isset($table_info['primary_key'])) {
         $msg = "This table (sq_{$tablename}) cannot be converted since it doesn't have a primary key.\n";
         $msg .= "A primary key is required to guarantee the chunking of data doesn't\n";
         $msg .= "miss anything and all data is fetched correctly from the table.\n";
         $msg .= "Skipping table.\n";
         pre_echo($msg);
         /**
          * 'restore' to the dest db
          * even though we switch straight back to the source
          * otherwise dal gets confused about which is which.
          */