/**
 * Returns the content of global concept IDs stream as text with local IDs
 *
 * @param mixed $instream - source data with global concept IDs
 */
function importTemplate()
{
    global $dir;
    if (!$_FILES['import_template']['size']) {
        $res = array("error" => 'Error occurred during upload - file had zero size');
    } else {
        $filename = $_FILES['import_template']['tmp_name'];
        $origfilename = $_FILES['import_template']['name'];
        //read tempfile
        $template = file_get_contents($filename);
        $res = convertTemplate($template, 1);
        if (!is_array($res)) {
            $res = array('template' => $res);
        }
        if (!@$res['error']) {
            //check if template with such name already exists
            /*while (file_exists($dir.$origfilename)){
                  $dir.$origfilename = $dir.$origfilename . "($cnt)";
              }*/
            $origfilename = getUniqueTemplateName($origfilename);
            $res2 = saveTemplate($res['template'], $origfilename);
            if (count(@$res['details_not_found']) > 0) {
                $res2['details_not_found'] = $res['details_not_found'];
            }
            $res = $res2;
        }
    }
    //header("Content-type: text/javascript");
    header('Content-type: application/json');
    print json_encode($res);
    //print json_format($res);
}
Exemple #2
0
     //###########################################
 //###########################################
 //			START TEMPLATE MANAGER
 //###########################################
 case "showTemplates":
     showTemplates($option);
     break;
 case "publishTemplate":
     publishTemplate();
     break;
 case "editKTemplate":
     editKTemplate($option);
     break;
 case "saveTemplate":
 case "applyTemplate":
     saveTemplate();
     break;
 case "chooseCSSTemplate":
     chooseCSSTemplate();
     break;
 case "editTemplateCSS":
     editTemplateCSS();
     break;
 case "saveTemplateCSS":
     saveTemplateCSS();
     break;
 case "cancelTemplate":
     cancelTemplate();
     break;
     /*case "previewTemplate" :
     		previewTemplate();
<?
require_once "lib_ref_admin.php";
require_once "lib_tpt.php";

$language = $_GET["l"];
$text = (isset($_GET["t"]) ? $_GET["t"] : null);
if (!$language) die("Invalid calling");
saveTemplate($language,$text);
echo "OK";
?>
function patch40()
{
    // CHECK THAT THEY ARE AT 3.1 LEVEL, IF NOT, LINK TO PATCH31
    // Check for ele_handle being 255 in formulize table
    global $xoopsDB;
    // note very odd use of LIKE as a clause of its own in SHOW statements, very strange, but that's what MySQL does
    $fieldStateSQL = "SHOW COLUMNS FROM " . $xoopsDB->prefix("formulize") . " LIKE 'ele_handle'";
    if (!($fieldStateRes = $xoopsDB->queryF($fieldStateSQL))) {
        print "Error: could not determine if your Formulize database structure is up to date.  Please contact <a href=\"mailto:formulize@freeformsolutions.ca\">Freeform Solutions</a> for assistance.<br>\n";
        return false;
    }
    $fieldStateData = $xoopsDB->fetchArray($fieldStateRes);
    $dataType = $fieldStateData['Type'];
    if ($dataType != "varchar(255)") {
        print "<h1>Your database schema is out of date.  You must run \"patch31\" before running the current patch.</h1>\n";
        print "<p><a href=\"" . XOOPS_URL . "/modules/formulize/admin/formindex.php?op=patch31\">Click here to run \"patch31\".</a></p>\n";
        return;
    }
    /* ======================================
     * We must check here for the latest change, so we can tell the user whether they need to update or not!!
     * We set needsPatch = false, and the alter to true if a patch is necessary
     * When false, we return nothing from this function, as a cue that no patch is required
     *
     * To specify what to check, simply update the four variables declared below this comment.
     * Set to false to ignore that level of checking
     *
     * THIS NEEDS TO BE UPDATED WHENEVER THERE IS A PATCH TO THE DATA STRUCTURE!!!
     *
     * IN ADDITION TO THE UPDATE HERE, THE mysql.sql FILE MUST BE UPDATED WITH THE REQUIRED CHANGES SO NEW INSTALLATIONS ARE UP TO DATE
     *
     * IT IS ALSO CRITICAL THAT THE PATCH PROCESS CAN BE RUN OVER AND OVER AGAIN NON-DESTRUCTIVELY
     *
     * ====================================== */
    $checkThisTable = 'formulize_screen_template';
    $checkThisField = false;
    // no particular field to check.
    $checkThisProperty = false;
    $checkPropertyForValue = false;
    $needsPatch = false;
    $tableCheckSql = "SELECT 1 FROM information_schema.tables WHERE table_name = '" . $xoopsDB->prefix(formulize_db_escape($checkThisTable)) . "'";
    $tableCheckRes = formulize_DBPatchCheckSQL($tableCheckSql, $needsPatch);
    // may modify needsPatch!
    if ($tableCheckRes and !$needsPatch and $checkThisField) {
        // table was found, and we're looking for a field in it
        $fieldCheckSql = "SHOW COLUMNS FROM " . $xoopsDB->prefix(formulize_db_escape($checkThisTable)) . " LIKE '" . formulize_db_escape($checkThisField) . "'";
        // note very odd use of LIKE as a clause of its own in SHOW statements, very strange, but that's what MySQL does
        $fieldCheckRes = formulize_DBPatchCheckSQL($fieldCheckSql, $needsPatch);
        // may modify needsPatch!
    }
    if ($fieldCheckRes and !$needsPatch and $checkPropertyForValue) {
        $fieldCheckArray = $xoopsDB->fetchArray($fieldCheckRes);
        if ($fieldCheckArray[$checkThisProperty] != $checkPropertyForValue) {
            $needsPatch = true;
        }
    }
    if (!$needsPatch and (!isset($_GET['op']) or $_GET['op'] != 'patch40' and $_GET['op'] != 'patchDB')) {
        return;
    }
    if (!isset($_POST['patch40'])) {
        print "<form action=\"ui.php?op=patchDB\" method=post>";
        print "<h1>Your database structure is not up to date!  Click the button below to apply the necesssary patch to the database.</h1>";
        print "<h2>Warning: this patch makes several changes to the database.  Backup your database prior to applying this patch!</h2>";
        print "<input type = submit name=patch40 value=\"Apply Database Patch for Formulize\">";
        print "</form>";
    } else {
        // PATCH LOGIC GOES HERE
        print "<h2>Patch Results:</h2>";
        $testsql = "SHOW TABLES";
        $resultst = $xoopsDB->query($testsql);
        while ($table = $xoopsDB->fetchRow($resultst)) {
            $existingTables[] = $table[0];
        }
        $sql = array();
        if (!in_array($xoopsDB->prefix("formulize_groupscope_settings"), $existingTables)) {
            $sql[] = "CREATE TABLE `" . $xoopsDB->prefix("formulize_groupscope_settings") . "` (\n  `groupscope_id` int(11) NOT NULL auto_increment,\n  `groupid` int(11) NOT NULL default 0,\n    `fid` int(11) NOT NULL default 0,\n  `view_groupid` int(11) NOT NULL default 0,\n  PRIMARY KEY (`groupscope_id`),\n  INDEX i_groupid (`groupid`),\n    INDEX i_fid (`fid`),\n  INDEX i_view_groupid (`view_groupid`)\n) ENGINE=MyISAM;";
        }
        if (!in_array($xoopsDB->prefix("formulize_group_filters"), $existingTables)) {
            $sql[] = "CREATE TABLE `" . $xoopsDB->prefix("formulize_group_filters") . "` (\n  `filterid` int(11) NOT NULL auto_increment,\n  `fid` int(11) NOT NULL default 0,\n  `groupid` int(11) NOT NULL default 0,\n  `filter` text NOT NULL,\n  PRIMARY KEY (`filterid`),\n  INDEX i_fid (`fid`),\n  INDEX i_groupid (`groupid`)\n) ENGINE=MyISAM;";
        }
        if (!in_array($xoopsDB->prefix("formulize_applications"), $existingTables)) {
            $sql[] = "CREATE TABLE `" . $xoopsDB->prefix("formulize_applications") . "` (\n  `appid` int(11) NOT NULL auto_increment,\n  `name` varchar(255) NOT NULL default '',\n  `description` text NOT NULL,\n  PRIMARY KEY (`appid`)\n) ENGINE=MyISAM;";
        }
        if (!in_array($xoopsDB->prefix("formulize_application_form_link"), $existingTables)) {
            $sql[] = "CREATE TABLE `" . $xoopsDB->prefix("formulize_application_form_link") . "` (\n  `linkid` int(11) NOT NULL auto_increment,\n  `appid` int(11) NOT NULL default 0,\n  `fid` int(11) NOT NULL default 0,\n  PRIMARY KEY (`linkid`),\n  INDEX i_fid (`fid`),\n  INDEX i_appid (`appid`)\n) ENGINE=MyISAM;";
        }
        if (!in_array($xoopsDB->prefix("formulize_screen_form"), $existingTables)) {
            $sql[] = "CREATE TABLE `" . $xoopsDB->prefix("formulize_screen_form") . "` (\n  `formid` int(11) NOT NULL auto_increment,\n  `sid` int(11) NOT NULL default 0,\n  `donedest` varchar(255) NOT NULL default '',\n  `savebuttontext` varchar(255) NOT NULL default '',\n  `alldonebuttontext` varchar(255) NOT NULL default '',\n  `displayheading` tinyint(1) NOT NULL default 0,\n  `reloadblank` tinyint(1) NOT NULL default 0,\n  `formelements` text,\n  PRIMARY KEY (`formid`),\n  INDEX i_sid (`sid`)\n) ENGINE=MyISAM;";
        }
        if (!in_array($xoopsDB->prefix("formulize_advanced_calculations"), $existingTables)) {
            $sql[] = "CREATE TABLE `" . $xoopsDB->prefix("formulize_advanced_calculations") . "` (\n  `acid` int(11) NOT NULL auto_increment,\n  `fid` int(11) NOT NULL default '0',\n  `name` varchar(255) NOT NULL default '',\n  `description` text NOT NULL,\n  `input` text NOT NULL,\n  `output` text NOT NULL,\n  `steps` text NOT NULL,\n  `steptitles` text NOT NULL,\n  `fltr_grps` text NOT NULL,\n  `fltr_grptitles` text NOT NULL,\n  PRIMARY KEY  (`acid`),\n  KEY `i_fid` (`fid`)\n) ENGINE=MyISAM;";
        }
        if (!in_array($xoopsDB->prefix("formulize_procedure_logs"), $existingTables)) {
            $sql[] = "CREATE TABLE `" . $xoopsDB->prefix("formulize_procedure_logs") . "` (\n  `proc_log_id` int(11) unsigned NOT NULL auto_increment,\n  `proc_id` int(11) NOT NULL,\n  `proc_datetime` datetime NOT NULL,\n  `proc_uid` mediumint(8) unsigned NOT NULL,\n  PRIMARY KEY (`proc_log_id`),\n  INDEX i_proc_id (proc_id),\n  INDEX i_proc_uid (proc_uid)\n) ENGINE=MyISAM;";
        }
        if (!in_array($xoopsDB->prefix("formulize_procedure_logs_params"), $existingTables)) {
            $sql[] = "CREATE TABLE `" . $xoopsDB->prefix("formulize_procedure_logs_params") . "` (\n  `proc_log_param_id` int(11) unsigned NOT NULL auto_increment,\n  `proc_log_id` int(11) unsigned NOT NULL,\n  `proc_log_param` varchar(255),\n  `proc_log_value` varchar(255),\n  PRIMARY KEY (`proc_log_param_id`),\n  INDEX i_proc_log_id (proc_log_id)\n) ENGINE=MyISAM;";
        }
        if (!in_array($xoopsDB->prefix("formulize_resource_mapping"), $existingTables)) {
            $sql[] = "CREATE TABLE `" . $xoopsDB->prefix("formulize_resource_mapping") . "` (\n    mapping_id int(11) NOT NULL auto_increment,\n    internal_id int(11) NOT NULL,\n    external_id int(11) NOT NULL,\n    resource_type int(4) NOT NULL,\n    mapping_active tinyint(1) NOT NULL,\n    PRIMARY KEY (mapping_id),\n    INDEX i_internal_id (internal_id),\n    INDEX i_external_id (external_id),\n    INDEX i_resource_type (resource_type)\n) ENGINE=MyISAM;";
        }
        if (!in_array($xoopsDB->prefix("formulize_deletion_logs"), $existingTables)) {
            $sql[] = "CREATE TABLE " . $xoopsDB->prefix("formulize_deletion_logs") . " (\n                  del_log_id int(11) unsigned NOT NULL auto_increment,\n                  form_id int(11) NOT NULL,\n                  entry_id int(7) NOT NULL,\n                  user_id mediumint(8) NOT NULL,\n                  context text,\n                  deletion_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n                  PRIMARY KEY (del_log_id),\n                  INDEX i_del_id (del_log_id)\n        ) ENGINE=MyISAM;";
        }
        if (!in_array($xoopsDB->prefix("formulize_screen_template"), $existingTables)) {
            $sql[] = "CREATE TABLE " . $xoopsDB->prefix("formulize_screen_template") . " (\n            templateid int(11) NOT NULL auto_increment,\n            sid int(11) NOT NULL default 0,\n            custom_code text NOT NULL,\n            template text NOT NULL,\n            PRIMARY KEY (`templateid`),\n            INDEX i_sid (`sid`)\n        ) ENGINE=MyISAM;";
        }
        // if this is a standalone installation, then we want to make sure the session id field in the DB is large enough to store whatever session id we might be working with
        if (file_exists(XOOPS_ROOT_PATH . "/integration_api.php")) {
            $sql['increase_session_id_size'] = "ALTER TABLE " . $xoopsDB->prefix("session") . " CHANGE `sess_id` `sess_id` varchar(60) NOT NULL";
        }
        $sql['add_encrypt'] = "ALTER TABLE " . $xoopsDB->prefix("formulize") . " ADD `ele_encrypt` tinyint(1) NOT NULL default '0'";
        $sql['add_lockedform'] = "ALTER TABLE " . $xoopsDB->prefix("formulize_id") . " ADD `lockedform` tinyint(1) NULL default NULL";
        $sql['drop_from_formulize_id_admin'] = "ALTER TABLE " . $xoopsDB->prefix("formulize_id") . " DROP `admin`";
        $sql['drop_from_formulize_id_groupe'] = "ALTER TABLE " . $xoopsDB->prefix("formulize_id") . " DROP `groupe`";
        $sql['drop_from_formulize_id_email'] = "ALTER TABLE " . $xoopsDB->prefix("formulize_id") . " DROP `email`";
        $sql['drop_from_formulize_id_expe'] = "ALTER TABLE " . $xoopsDB->prefix("formulize_id") . " DROP `expe`";
        $sql['drop_from_formulize_id_maxentries'] = "ALTER TABLE " . $xoopsDB->prefix("formulize_id") . " DROP `maxentries`";
        $sql['drop_from_formulize_id_even'] = "ALTER TABLE " . $xoopsDB->prefix("formulize_id") . " DROP `even`";
        $sql['drop_from_formulize_id_odd'] = "ALTER TABLE " . $xoopsDB->prefix("formulize_id") . " DROP `odd`";
        $sql['drop_from_formulize_id_groupscope'] = "ALTER TABLE " . $xoopsDB->prefix("formulize_id") . " DROP `groupscope`";
        $sql['drop_from_formulize_id_showviewentries'] = "ALTER TABLE " . $xoopsDB->prefix("formulize_id") . " DROP `showviewentries`";
        $sql['add_filtersettings'] = "ALTER TABLE " . $xoopsDB->prefix("formulize") . " ADD `ele_filtersettings` text NOT NULL";
        $sql['ele_type_100'] = "ALTER TABLE " . $xoopsDB->prefix("formulize") . " CHANGE `ele_type` `ele_type` varchar(100) NOT NULL default ''";
        $sql['ele_disabled_text'] = "ALTER TABLE " . $xoopsDB->prefix("formulize") . " CHANGE `ele_disabled` `ele_disabled` text NOT NULL ";
        $sql['ele_display_dropindex'] = "ALTER TABLE " . $xoopsDB->prefix("formulize") . " DROP INDEX `ele_display`";
        $sql['ele_display_text'] = "ALTER TABLE " . $xoopsDB->prefix("formulize") . " CHANGE `ele_display` `ele_display` text NOT NULL ";
        $sql['ele_display_addindex'] = "ALTER TABLE " . $xoopsDB->prefix("formulize") . " ADD INDEX `ele_display` ( `ele_display` ( 255 ) )";
        $sql['sep_to_areamodif'] = "UPDATE " . $xoopsDB->prefix("formulize") . " SET ele_type='areamodif' WHERE ele_type='sep'";
        $sql['add_defaultform'] = "ALTER TABLE " . $xoopsDB->prefix("formulize_id") . " ADD `defaultform` int(11) NOT NULL default 0";
        $sql['add_defaultlist'] = "ALTER TABLE " . $xoopsDB->prefix("formulize_id") . " ADD `defaultlist` int(11) NOT NULL default 0";
        $sql['add_menutext'] = "ALTER TABLE " . $xoopsDB->prefix("formulize_id") . " ADD `menutext` varchar(255) default 'Use the form\\'s title'";
        $sql['add_useadvcalcs'] = "ALTER TABLE " . $xoopsDB->prefix("formulize_screen_listofentries") . " ADD `useadvcalcs` varchar(255) NOT NULL default ''";
        $sql['add_not_elementemail'] = "ALTER TABLE " . $xoopsDB->prefix("formulize_notification_conditions") . " ADD `not_cons_elementemail` smallint(5) NOT NULL default 0";
        $sql['add_form_handle'] = "ALTER TABLE " . $xoopsDB->prefix("formulize_id") . " ADD `form_handle` varchar(255) NOT NULL";
        $sql['id_form_to_form_handle'] = "UPDATE " . $xoopsDB->prefix("formulize_id") . " SET form_handle = id_form WHERE form_handle IS NULL OR form_handle = ''";
        $sql['add_dedisplay'] = "ALTER TABLE " . $xoopsDB->prefix("formulize_screen_listofentries") . " ADD `dedisplay` int(1) NOT NULL";
        $sql['add_store_revisions'] = "ALTER TABLE " . $xoopsDB->prefix("formulize_id") . " ADD `store_revisions` tinyint(1) NOT NULL default '0'";
        $sql['add_finishisdone'] = "ALTER TABLE " . $xoopsDB->prefix("formulize_screen_multipage") . " ADD `finishisdone` tinyint(1) NOT NULL default 0";
        $sql['add_toptext'] = "ALTER TABLE " . $xoopsDB->prefix("formulize_screen_multipage") . " ADD `toptemplate` text NOT NULL";
        $sql['add_elementtext'] = "ALTER TABLE " . $xoopsDB->prefix("formulize_screen_multipage") . " ADD `elementtemplate` text NOT NULL";
        $sql['add_bottomtext'] = "ALTER TABLE " . $xoopsDB->prefix("formulize_screen_multipage") . " ADD `bottomtemplate` text NOT NULL";
        $sql['add_formelements'] = "ALTER TABLE " . $xoopsDB->prefix("formulize_screen_form") . " ADD `formelements` text";
        $sql['add_on_before_save'] = "ALTER TABLE " . $xoopsDB->prefix("formulize_id") . " ADD `on_before_save` text";
        $sql['add_on_after_save'] = "ALTER TABLE " . $xoopsDB->prefix("formulize_id") . " ADD `on_after_save` text";
        $sql['add_custom_edit_check'] = "ALTER TABLE " . $xoopsDB->prefix("formulize_id") . " ADD `custom_edit_check` text";
        $sql['add_form_note'] = "ALTER TABLE " . $xoopsDB->prefix("formulize_id") . " ADD `note` text";
        $sql['add_use_default_when_blank'] = "ALTER TABLE " . $xoopsDB->prefix("formulize") . " ADD `ele_use_default_when_blank` tinyint(1) NOT NULL default '0'";
        $sql['add_global_search_to_saved_view'] = "ALTER TABLE " . $xoopsDB->prefix("formulize_saved_views") . " ADD `sv_global_search` text";
        $sql['add_application_code'] = "ALTER TABLE " . $xoopsDB->prefix("formulize_applications") . " ADD `custom_code` mediumtext";
        $sql['add_note_to_menu_links'] = "ALTER TABLE " . $xoopsDB->prefix("formulize_menu_links") . " ADD `note` text";
        foreach ($sql as $key => $thissql) {
            if (!($result = $xoopsDB->query($thissql))) {
                if ($key === "add_encrypt") {
                    print "ele_encrypt field already added.  result: OK<br>";
                } elseif ($key === "add_lockedform") {
                    print "lockedform field already added.  result: OK<br>";
                } elseif ($key === "add_filtersettings") {
                    print "element filtersettings field already added.  result: OK<br>";
                } elseif ($key === "add_defaultform") {
                    print "defaultform field already added.  result: OK<br>";
                } elseif ($key === "add_defaultlist") {
                    print "defaultlist field already added.  result: OK<br>";
                } elseif ($key === "add_menutext") {
                    print "menutext field already added.  result: OK<br>";
                } elseif ($key === "add_useadvcalcs") {
                    print "useadvcalcs field already added.  result: OK<br>";
                } elseif ($key === "add_not_elementemail") {
                    print "elementemail notification option already added.  result: OK<br>";
                } elseif ($key === "add_form_handle") {
                    print "form handles already added.  result: OK<br>";
                } elseif ($key === "add_dedisplay") {
                    print "dedisplay already added.  result: OK<br>";
                } elseif ($key === "add_store_revisions") {
                    print "store_revisions already added.  result: OK<br>";
                } elseif ($key === "add_finishisdone") {
                    print "finishisdone for multipage forms already added.  result: OK<br>";
                } elseif ($key === "add_toptext") {
                    print "toptemplate already added for multipage screens.  result: OK<br>";
                } elseif ($key === "add_elementtext") {
                    print "elementtemplate already added for multipage screens.  result: OK<br>";
                } elseif ($key === "add_bottomtext") {
                    print "bottomtemplate already added for multipage screens.  result: OK<br>";
                } elseif ($key === "add_formelements") {
                    print "formelements field already added for single page screens.  result: OK<br>";
                } elseif ($key === "add_on_before_save") {
                    print "on_before_save field already added.  result: OK<br>";
                } elseif ($key === "add_on_after_save") {
                    print "on_after_save field already added.  result: OK<br>";
                } elseif ($key === "add_custom_edit_check") {
                    print "custom_edit_check field already added.  result: OK<br>";
                } elseif ($key === "add_form_note") {
                    print "form note field already added.  result: OK<br>";
                } elseif ($key === "add_use_default_when_blank") {
                    print "use default when blank already added.  result: OK<br>";
                } elseif ($key === "add_global_search_to_saved_view") {
                    print "global search saved view already added.  result: OK<br>";
                } elseif ($key === "add_application_code") {
                    print "application custom_code field added.  result: OK<br>";
                } elseif ($key === "add_note_to_menu_links") {
                    print "note already added for menu links.  result: OK<br>";
                } elseif (strstr($key, 'drop_from_formulize_id_')) {
                    continue;
                } else {
                    exit("Error patching DB for Formulize 4.0. SQL dump:<br>" . $thissql . "<br>" . $xoopsDB->error() . "<br>Please contact <a href=mailto:formulize@freeformsolutions.ca>Freeform Solutions</a> for assistance.");
                }
            }
        }
        // if there is a framework handles table present, then we need to check for a few things to ensure the integrity of code and our ability to disambiguate inputs to the API
        if (in_array($xoopsDB->prefix("formulize_framework_elements"), $existingTables)) {
            // need to change rules...framework handles must now be globally unique, so we can disambiguate them from each other when we are passed just a framework handle
            $uniqueSQL = "SELECT elements.ele_caption, elements.ele_id, elements.ele_handle, handles.fe_handle, handles.fe_frame_id FROM " . $xoopsDB->prefix("formulize") . " as elements, " . $xoopsDB->prefix("formulize_framework_elements") . " as handles WHERE EXISTS (SELECT 1 FROM " . $xoopsDB->prefix("formulize_framework_elements") . " as checkhandles WHERE handles.fe_handle = checkhandles.fe_handle AND handles.fe_element_id != checkhandles.fe_element_id) AND handles.fe_element_id = elements.ele_id AND handles.fe_handle != \"\" ORDER BY handles.fe_handle";
            $uniqueRes = $xoopsDB->query($uniqueSQL);
            $haveWarning = false;
            $warningIdentifier = array();
            $warningContents = array();
            if ($xoopsDB->getRowsNum($uniqueRes)) {
                $haveWarning = true;
                $warningIdentifier[] = "<li>You have some \"framework handles\" which are the same between different frameworks.</li>";
                ob_start();
                print "<ul>";
                $prevHandle = "";
                while ($uniqueArray = $xoopsDB->fetchArray($uniqueRes)) {
                    if ($uniqueArray['fe_handle'] != $prevHandle) {
                        if ($prevHandle != "") {
                            // need to finish previous set and print out what's missing
                            print "</li>";
                        }
                        print "<li>Framework handle: <b>" . $uniqueArray['fe_handle'] . "</b> is used in more than one place:<br>";
                    }
                    $prevHandle = $uniqueArray['fe_handle'];
                    print "&nbsp;&nbsp;&nbsp;&nbsp;In framework " . $uniqueArray['fe_frame_id'] . ", it is used for element " . $uniqueArray['ele_id'] . " (" . $uniqueArray['ele_caption'] . ")<br>";
                    if ($uniqueArray['fe_handle'] != $uniqueArray['ele_handle']) {
                        print "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;For element " . $uniqueArray['ele_id'] . ", use the element's data handle instead: <b>" . $uniqueArray['ele_handle'] . "</b><br>";
                    }
                }
                // dump the last stuff we had found in the loop
                print "</li>";
                print "</ul>";
                $warningContents[] = ob_get_clean();
            }
            // need to disambiguate framework handles and elements' data handles.
            // no framework handle can be identical to the text of any data handle, unless they refer to the same element
            // So look up all the elements that have a data handle that matches a framework handle, which is not referring to the same element
            $handleSQL = "SELECT elements.ele_id, elements.ele_caption, elements.ele_handle, handles.fe_frame_id, handles.fe_handle, handles.fe_element_id, e2.ele_caption as handlecap, e2.ele_handle as newhandle FROM " . $xoopsDB->prefix("formulize") . " AS elements, " . $xoopsDB->prefix("formulize_framework_elements") . " AS handles, " . $xoopsDB->prefix("formulize") . " AS e2 WHERE elements.ele_handle = handles.fe_handle AND handles.fe_element_id != elements.ele_id AND handles.fe_element_id = e2.ele_id ORDER BY elements.id_form, elements.ele_order";
            $handleRes = $xoopsDB->query($handleSQL);
            if ($xoopsDB->getRowsNum($handleRes) > 0) {
                $haveWarning = true;
                $warningIdentifier[] = "<li>You have some \"data handles\" which are identical to the \"framework handles\" of other elements.</li>";
                ob_start();
                print "<ul>";
                while ($handleArray = $xoopsDB->fetchArray($handleRes)) {
                    print "<li>" . $handleArray['handlecap'] . " (element " . $handleArray['fe_element_id'] . ") &mdash framework handle: <b>" . $handleArray['fe_handle'] . "</b> in framework " . $handleArray['fe_frame_id'] . "<br>";
                    print "&nbsp;&nbsp;&nbsp;&nbsp;Use the element's data handle instead: <b>" . $handleArray['newhandle'] . "</b></li>";
                }
                print "</ul>";
                $warningContents[] = ob_get_clean();
            }
        }
        if ($haveWarning) {
            print "<hr><p>MAJOR WARNING:</p>";
            print "<ol>";
            print implode("\n", $warningIdentifier);
            print "</ol>";
            print "<p>Framework handles are deprecated in Formulize 4, and having framework handles that are not entirely unique can now lead to serious errors in some situations.  However, we cannot automatically fix this situation for you, because you may have used the framework handles in programming code in your website.  If we try an automatic fix, we could break some other parts of your website.</p><p>Recommended actions:</p><p>1. Note down the following framework handles for the following elements (copy this information to a file, print this page, etc):<br>";
            print implode("\n", $warningContents);
            print "</p><p>2. Determine if you have any saved views based on a framework, that include the elements (columns) mentioned above.</p>";
            print "<p>3. For any elements mentioned above that are included in framework-based saved views, change their framework handles as suggested above.</p>";
            print "<p>4. Open up the affected saved views, and re-add the changed elements (columns) to them.  Search terms on changed columns will need to be respecified too, as well as sorting options.  Then re-save the view.  <b>Your users will need to do this too, if they have personal saved views which you cannot access.</b></p>";
            print "<p>5. Determine where you may be using the <b>framework handles</b> mentioned above in any programming code in your website.</p>";
            print "<p>6. For any elements where you are using the framework handles in programming code, change those framework handles as suggested above. You will need to make these changes in the framework configuration settings, as well as in the actual programming code where you are referring to the handle.</p>";
            print "<p> --- </p>";
            print "<p><b>You probably don't need to make all of the changes suggested above!</b>  You only need to make changes in places where there are saved views and/or programming code that uses the elements mentioned above.  For some websites, that will mean you don't have to make any changes (ie: if there are no saved views based on a framework, and you have no programming code referring to frameworks).</p>";
            print "<p> --- </p>";
            print "<p><b>You can re-run this patch after making changes.  If you do not get this warning, then your site should be OK.</b></p>";
            print "<p>If you have any questions about this upgrade issue, please contact <a href=mailto:formulize@freeformsolutions.ca>Freeform Solutions</a> for assistance.</p>";
        }
        //create new menus table
        if (!in_array($xoopsDB->prefix("formulize_menu_links"), $existingTables)) {
            $menusql[] = "CREATE TABLE `" . $xoopsDB->prefix("formulize_menu_links") . "` (\n            `menu_id` int(11) unsigned NOT NULL auto_increment,\n            `appid` int(11) unsigned NOT NULL,\n            `screen` varchar(11),\n            `rank` int(11),\n            `url` varchar(255),\n            `link_text` varchar(255),\n            PRIMARY KEY (`menu_id`),\n            INDEX i_menus_appid (appid)\n            );";
            $menusql[] = "CREATE TABLE `" . $xoopsDB->prefix("formulize_menu_permissions") . "` (\n            `permission_id` int(11) unsigned NOT NULL auto_increment,\n            `menu_id` int(11) unsigned NOT NULL,\n            `group_id` int(11) unsigned NOT NULL,\n            `default_screen` tinyint(1) NOT NULL default '0',\n            PRIMARY KEY (`permission_id`),\n            INDEX i_menu_permissions (menu_id)\n            );";
            print "Creating new menu_links and menu_permissions tables...<br>";
            foreach ($menusql as $key => $thissql) {
                if (!($result = $xoopsDB->query($thissql))) {
                    exit("Error patching DB for Formulize 4.0. SQL dump:<br>" . $thissql . "<br>" . $xoopsDB->error() . "<br>Please contact <a href=mailto:formulize@freeformsolutions.ca>Freeform Solutions</a> for assistance.");
                }
            }
            // populate new menus tables with existing menu entries
            $application_handler = xoops_getmodulehandler('applications', 'formulize');
            $form_handler = xoops_getmodulehandler('forms', 'formulize');
            $allApplications = $application_handler->getAllApplications();
            $menuTexts = array();
            $i = 0;
            foreach ($allApplications as $thisApplication) {
                $forms = $thisApplication->getVar('forms');
                foreach ($forms as $thisForm) {
                    $thisFormObject = $form_handler->get($thisForm);
                    if ($menuText = $thisFormObject->getVar('menutext')) {
                        saveMenuEntryAndPermissionsSQL($thisFormObject->getVar('id_form'), $thisApplication->getVar("appid"), $i, $menuText);
                    }
                    $i++;
                }
                $i = 0;
            }
            $formsWithNoApplication = $form_handler->getFormsByApplication(0, true);
            // true forces ids not objects to be returned
            foreach ($formsWithNoApplication as $thisForm) {
                $thisFormObject = $form_handler->get($thisForm);
                if ($menuText = $thisFormObject->getVar('menutext')) {
                    saveMenuEntryAndPermissionsSQL($thisFormObject->getVar('id_form'), 0, $i, $menuText);
                }
                $i++;
            }
        }
        // need to update multiple select boxes for new data structure
        // $xoopsDB->prefix("formulize")
        // 1. get a list of all elements that are linked selectboxes that support only single values
        $selectBoxesSQL = "SELECT id_form, ele_id FROM " . $xoopsDB->prefix("formulize") . " WHERE ele_type = 'select'";
        $selectBoxRes = $xoopsDB->query($selectBoxesSQL);
        if ($xoopsDB->getRowsNum($selectBoxRes) > 0) {
            while ($handleArray = $xoopsDB->fetchArray($selectBoxRes)) {
                $metaData = formulize_getElementMetaData($handleArray['ele_id']);
                $ele_value = unserialize($metaData['ele_value']);
                // select only single option, linked select boxes
                if (!$ele_value[1] and strstr($ele_value[2], "#*=:*")) {
                    $successSelectBox = convertSelectBoxToSingle($xoopsDB->prefix('formulize_' . $handleArray['id_form']), $handleArray['ele_id']);
                    if (!$successSelectBox) {
                        print "could not convert column " . $handleArray['ele_id'] . " in table " . $xoopsDB->prefix('formulize_' . $handleArray['id_form']) . "<br>";
                    }
                }
            }
        }
        // if the relationship link option, unified_delete, does not exist, create the field and default to the unified_display setting value
        $sql = $xoopsDB->query("show columns from " . $xoopsDB->prefix("formulize_framework_links") . " where Field = 'fl_unified_delete'");
        if (0 == $xoopsDB->getRowsNum($sql)) {
            $sql = "ALTER TABLE " . $xoopsDB->prefix("formulize_framework_links") . " ADD `fl_unified_delete` smallint(5)";
            if ($udres1 = $xoopsDB->query($sql)) {
                $sql = "update " . $xoopsDB->prefix("formulize_framework_links") . " set `fl_unified_delete` = `fl_unified_display`";
                $udres2 = $xoopsDB->query($sql);
            }
            if (!$udres1 or !$udres2) {
                print "Error updating relationships with unified delete option.  SQL dump:<br>" . $thissql . "<br>" . $xoopsDB->error() . "<br>Please contact <a href=mailto:formulize@freeformsolutions.ca>Freeform Solutions</a> for assistance.";
            } else {
                print "Updating relationships with unified delete option.  result: OK<br>";
            }
        }
        // CONVERTING EXISTING TEMPLATES IN DB TO TEMPLATE FILES
        $screenpathname = XOOPS_ROOT_PATH . "/modules/formulize/templates/screens/default/";
        $templateSQL = "SELECT sid, toptemplate, listtemplate, bottomtemplate FROM " . $xoopsDB->prefix("formulize") . "_screen_listofentries";
        $templateRes = $xoopsDB->query($templateSQL);
        if ($xoopsDB->getRowsNum($templateRes) > 0) {
            while ($handleArray = $xoopsDB->fetchArray($templateRes)) {
                if (!file_exists($screenpathname . $handleArray['sid'])) {
                    $pathname = $screenpathname . $handleArray['sid'] . "/";
                    mkdir($pathname, 0777, true);
                    if (!is_writable($pathname)) {
                        chmod($pathname, 0777);
                    }
                    saveTemplate($handleArray['toptemplate'], $handleArray['sid'], "toptemplate");
                    saveTemplate($handleArray['bottomtemplate'], $handleArray['sid'], "bottomtemplate");
                    saveTemplate($handleArray['listtemplate'], $handleArray['sid'], "listtemplate");
                } else {
                    print "screen templates for screen " . $handleArray['sid'] . " already exist. result: OK<br>";
                }
            }
        }
        $multitemplateSQL = "SELECT sid, toptemplate, elementtemplate, bottomtemplate FROM " . $xoopsDB->prefix("formulize") . "_screen_multipage";
        $multitemplateRes = $xoopsDB->query($multitemplateSQL);
        if ($xoopsDB->getRowsNum($multitemplateRes) > 0) {
            while ($handleArray = $xoopsDB->fetchArray($multitemplateRes)) {
                if (!file_exists($screenpathname . $handleArray['sid'])) {
                    $pathname = $screenpathname . $handleArray['sid'] . "/";
                    mkdir($pathname, 0777, true);
                    if (!is_writable($pathname)) {
                        chmod($pathname, 0777);
                    }
                    saveTemplate($handleArray['toptemplate'], $handleArray['sid'], "toptemplate");
                    saveTemplate($handleArray['bottomtemplate'], $handleArray['sid'], "bottomtemplate");
                    saveTemplate($handleArray['elementtemplate'], $handleArray['sid'], "elementtemplate");
                } else {
                    print "screen templates for screen " . $handleArray['sid'] . " already exist. result: OK<br>";
                }
            }
        }
        print "DB updates completed.  result: OK";
    }
}
Exemple #5
0
    putRGOptions($RGTMPL_LIST);
} else {
    if ($function == 'newTemplate') {
        newTemplate($tmpl_name);
    } else {
        if ($function == 'delTemplate') {
            delTemplate($tmpl_name);
        } else {
            if ($function == 'getStyle') {
                getStyle($tmpl_name);
            } else {
                if ($function == 'getTemplate') {
                    getTemplate($tmpl_name);
                } else {
                    if ($function == 'saveTemplate') {
                        saveTemplate($tmpl_name);
                    }
                }
            }
        }
    }
}
### FUNCTIONS
function delTemplate($tmplName)
{
    $shortname = $tmplName;
    $shortname = preg_replace("/^[\\.]+/", '', $tmplName);
    if ($tmplName == "../napc") {
        echo "ERROR: {$tmplName} can not be removed";
        return;
    }
<?php

require "_globals.php";
require SECURITY;
if (isset($_POST["submit"])) {
    saveTemplate($_POST["template_select"]);
    $message = "1 Template has been updated.";
}
$options = pullTemplates($_POST["template_select"]);
?>

<?php 
getHeader("admin");
?>

<script type="text/javascript" src="<?php 
echo PATHTOHTML . PATHTOADMIN;
?>
/ckeditor/ckeditor.js"></script>

<h3>Edit Report & Mail Templates</h3>

<?php 
echo buildMessage($message);
?>

<form action="<?php 
echo $_SERVER["PHP_SELF"];
?>
" method="post">
<h4>Templates</h4>
Exemple #7
0
    //load scheduled shift
    $shiftID = loadScheduleShift(date("d/m/Y", $lastSunday));
    $s = buildSchedule($shiftID);
    if ($shiftID > "0") {
        $jobs = buildJobArray();
        $employee = loadSortedEmployees();
        $empSchedule = loadSchedule(date("Y", $lastSunday), date("m", $lastSunday), date("d", $lastSunday));
        $shiftSaved = true;
        //show empty dates
    } else {
        $showCalendar = true;
    }
}
//save template
if ($_POST["procedure"] == "SaveTemp") {
    saveTemplate($_POST["template_name"], $shiftID, date("d/m/Y", $lastSunday));
} else {
    if ($_POST["procedure"] == "LoadTemp") {
        loadTemplate($_POST["tmp_id"]);
        $d = split("/", $theSunday);
        $s = buildSchedule($shiftID);
        if ($shiftID > "0") {
            $jobs = buildJobArray();
            $employee = loadSortedEmployees();
            $empSchedule = loadSchedule($d[2], $d[1], $d[0]);
        }
    }
}
padBegin(6, 6);
?>