function getTableList() { global $TABLE_PREFIX, $APP; // get table names $mysqlTables = getMysqlTablesWithPrefix(); $schemaTables = getSchemaTables(); // create multi query $tables = array(); $tableRowCounts = array(); foreach ($schemaTables as $tableName) { $tableNameWithPrefix = getTableNameWithPrefix($tableName); if (in_array($tableNameWithPrefix, $mysqlTables)) { $rowCount = mysql_count($tableNameWithPrefix); } $localTableSchema = loadSchema($tableName); array_push($tables, array('tableName' => $tableName, 'menuName' => @$localTableSchema['menuName'], 'menuType' => @$localTableSchema['menuType'], 'menuOrder' => @$localTableSchema['menuOrder'], 'menuHidden' => @$localTableSchema['menuHidden'], 'tableHidden' => @$localTableSchema['tableHidden'], '_indent' => @$localTableSchema['_indent'], 'recordCount' => $rowCount)); } // sort table list uasort($tables, '_sortMenusByOrder'); // return $tables; }
function _upgradeToVersion1_04() { global $SETTINGS, $APP; if ($SETTINGS['programVersion'] >= '1.04') { return; } // update schema files with new upload fields (checkboxes) foreach (getSchemaTables() as $tableName) { $schema = loadSchema($tableName); foreach (array_keys($schema) as $fieldname) { $fieldSchema =& $schema[$fieldname]; if (@$fieldSchema['type'] != 'upload') { continue; } // skip all but upload fields // add fields if (!array_key_exists('checkMaxUploadSize', $fieldSchema)) { $fieldSchema['checkMaxUploadSize'] = !empty($fieldSchema['maxUploadSizeKB']); } if (!array_key_exists('checkMaxUploads', $fieldSchema)) { $fieldSchema['checkMaxUploads'] = '1'; } if (!array_key_exists('resizeOversizedImages', $fieldSchema)) { $fieldSchema['resizeOversizedImages'] = $fieldSchema['maxImageHeight'] && $fieldSchema['maxImageWidth']; } if (!array_key_exists('createThumbnails', $fieldSchema)) { $fieldSchema['createThumbnails'] = $fieldSchema['maxThumbnailHeight'] && $fieldSchema['maxThumbnailWidth']; } if (!array_key_exists('customUploadDir', $fieldSchema)) { $fieldSchema['customUploadDir'] = ''; } if (!array_key_exists('customUploadUrl', $fieldSchema)) { $fieldSchema['customUploadUrl'] = ''; } if (!array_key_exists('infoField1', $fieldSchema)) { $fieldSchema['infoField1'] = ''; } if (!array_key_exists('infoField2', $fieldSchema)) { $fieldSchema['infoField2'] = ''; } if (!array_key_exists('infoField3', $fieldSchema)) { $fieldSchema['infoField3'] = ''; } if (!array_key_exists('infoField4', $fieldSchema)) { $fieldSchema['infoField4'] = ''; } if (!array_key_exists('infoField5', $fieldSchema)) { $fieldSchema['infoField5'] = ''; } } saveSchema($tableName, $schema); } saveAndRefresh('1.04'); }
function getTablesAndFieldnames() { global $APP; $tablesAndFields = array(); // foreach (getSchemaTables() as $tableName) { $schema = loadSchema($tableName); foreach ($schema as $fieldname => $fieldSchema) { if (!is_array($fieldSchema)) { continue; } // skip table metadata - fields are arrays if (@$fieldSchema['type'] == 'separator') { continue; } // skip separators if (@$fieldSchema['type'] == 'relatedRecords') { continue; } // skip $tablesAndFields[$tableName][] = $fieldname; } } // sort tablenames (fieldnames are already sorted by saveSchema) ksort($tablesAndFields); // return $tablesAndFields; }
<?php foreach ($db_conn as $conn) { if ($table->getConnID() == $conn->getID()) { echo '<OPTION VALUE = "' . $conn->getID() . '" SELECTED>' . $conn->getName() . '</OPTION>'; } else { echo '<OPTION VALUE = "' . $conn->getID() . '">' . $conn->getName() . '</OPTION>'; } } ?> </select> --> <label>Name* :</label> <select id="name" name="name" placeholder="Table Name" type="text"> <OPTION VALUE="-1"></OPTION> <?php echo getSchemaTables($table->getConnID() . ":" . $table->getName()); ?> </select> <label>Description* :</label> <input id="desc" name="desc" placeholder="Description" type="text" value="<?php echo $table->getDesc(); ?> "> <label>Search Field* :</label> <input id="pkfield" name="pkfield" placeholder="Name of Search Field" type="text" value="<?php echo $table->getPKField(); ?> "> <label>Public Access* :</label> <select id="public" name="public" placeholder="Public Access"> <option value="0" <?php
function _getMenuList() { global $APP, $CURRENT_USER; $menus = array(); $selectedMenu = getFirstDefinedValue(@$APP['selectedMenu'], @$_REQUEST['menu'], 'home'); $menuOrder = 0; // get schema files foreach (getSchemaTables() as $tableName) { $schema = loadSchema($tableName); if (!@$schema['menuType']) { continue; } if (@$schema['menuHidden']) { continue; } $menuOrder = max($menuOrder, @$schema['menuOrder']); // add menu items $thisMenu = array(); $thisMenu['schema'] = $schema; $thisMenu['menuType'] = $schema['menuType']; $thisMenu['menuName'] = $schema['menuName']; $thisMenu['menuOrder'] = $schema['menuOrder']; $thisMenu['tableName'] = $tableName; $thisMenu['isSelected'] = $selectedMenu == $tableName; $thisMenu['_indent'] = @$schema['_indent']; $thisMenu['_disableView'] = @$schema['_disableView']; $thisMenu['link'] = "?menu={$tableName}"; $thisMenu['linkTarget'] = ''; $thisMenu['linkMessage'] = ''; if ($schema['menuType'] == 'link') { $isExternalLink = @$schema['_linkTarget'] != 'iframe'; $setTargetBlank = $isExternalLink && (@$schema['_targetBlank'] || @$schema['_linkTarget'] == 'new'); // _targetBlank is the old schema format if ($isExternalLink) { $thisMenu['link'] = $schema['_url']; } if ($setTargetBlank) { $thisMenu['linkTarget'] = 'target="_blank"'; } if ($isExternalLink) { $thisMenu['linkMessage'] = @$schema['_linkMessage']; } // don't show js alert() for iframe links (show them at top of iframe page) } array_push($menus, $thisMenu); } // add admin menus $showAdminAtTop = false; if ($showAdminAtTop) { $menuOrder = -100; } $menus = array_merge($menus, _getAdminMenus($menuOrder)); // sort menus by order value uasort($menus, '_sortMenusByOrder'); $menus = array_values($menus); // re-index elements to match sort order (for operation below) // allow plugins to customize the menu while it's still an easily managable array $menus = applyFilters('menulinks_array', $menus); // set isSelected for menuGroups $groupChildSelected = false; for ($index = count($menus) - 1; $index >= 0; $index--) { $menu =& $menus[$index]; if ($menu['menuType'] == 'menugroup') { if ($groupChildSelected) { $menu['isSelected'] = true; $groupChildSelected = false; } } else { if ($menu['isSelected']) { $groupChildSelected = true; } } unset($menu); } // return $menus; }
function _createNewDemo() { global $TABLE_PREFIX; ### $maxAttempts = 12; $attempts = 0; $schemaTables = getSchemaTables(); $demoNum = sprintf("%.3f", array_sum(explode(' ', microtime()))); // eg: 1243448178.000 - allows for 999 demos to be created a second while (++$attempts <= $maxAttempts) { $demoNum = sprintf("%.3f", $demoNum + 0.001); $demoPrefix = "{$TABLE_PREFIX}(demo{$demoNum})_"; $demoPrefix = str_replace('.', '-', $demoPrefix); // . isn't allowed in tablenames foreach ($schemaTables as $tableName) { $sourceTable = "{$TABLE_PREFIX}{$tableName}"; $targetTable = "{$demoPrefix}{$tableName}"; if (strlen($targetTable) > 64) { die("Couldn't create demo table ({$targetTable}) as table name exceeded 64 characters. Try shortening your table prefix or table names."); } // create table if (!@mysql_query("CREATE TABLE `{$targetTable}` LIKE `{$sourceTable}`")) { continue 2; } // skip to next demoNum in while loop // copy rows @mysql_query("INSERT INTO `{$targetTable}` SELECT * FROM `{$sourceTable}`") or die("MySQL Error: " . htmlencode(mysql_error()) . "\n"); } break; } if ($attempts > $maxAttempts) { die("Error: Couldn't create demo after {$maxAttempts} attempts! Please contact us and let us know about this error!"); } // return $demoNum; }
function getSchemaPresets() { global $APP; $schemaPresets = array(); // get schema tablenames $schemaTables = array(); $schemaPresetDir = DATA_DIR . '/schemaPresets/'; foreach (getSchemaTables($schemaPresetDir) as $tableName) { $tableSchema = loadSchema($tableName, $schemaPresetDir); $menuName = @$tableSchema['menuName'] ? $tableSchema['menuName'] : $tableName; $schemaPresets[$tableName] = @$tableSchema['menuName']; } return $schemaPresets; }
function getTableRow($record, $value, $formType) { global $TABLE_PREFIX; // load access list $accessList = array(); if (@$_REQUEST['num']) { $query = "SELECT * FROM `{$TABLE_PREFIX}_accesslist` WHERE userNum = '" . mysql_escape($_REQUEST['num']) . "'"; $result = mysql_query($query) or die("MySQL Error: " . htmlencode(mysql_error()) . "\n"); while ($record = mysql_fetch_assoc($result)) { $accessList[$record['tableName']] = $record; } } // get section list $sectionList = array(); foreach (getSchemaTables() as $tableName) { $schema = loadSchema($tableName); $allowedMenuTypes = array('single', 'multi', 'category', 'menugroup', 'link', 'custom'); if (!in_array(@$schema['menuType'], $allowedMenuTypes)) { continue; } $thisMenu = array(); $thisMenu['menuName'] = htmlencode($schema['menuName']); if (@$schema['menuType'] != 'menugroup') { $thisMenu['menuName'] = ' ' . $thisMenu['menuName']; } if (@$schema['_indent']) { $thisMenu['menuName'] = ' ' . $thisMenu['menuName']; } $thisMenu['menuOrder'] = $schema['menuOrder']; $thisMenu['tableName'] = $tableName; $thisMenu['menuType'] = $schema['menuType']; array_push($sectionList, $thisMenu); } uasort($sectionList, '_sortMenusByOrder'); // sort menus by order value // display field $allAccessLevel = @$accessList['all']['accessLevel']; $sectionsDivStyle = $allAccessLevel != 1 ? "display: none;" : ''; // ob_start(); ?> <tr> <td valign="top" style="padding-top: 2px"><?php echo $this->label; ?> </td> <td> <table border="0" cellspacing="1" cellpadding="0"> <thead> <tr> <th width="305"><?php et('Section Name'); ?> </th> <th width="115" style="text-align: center"><?php et('Access'); ?> </th> <th width="100" style="text-align: center"><?php et('Max Records'); ?> </th> </tr> </thead> <tr> <td class="listRow listRowOdd"><?php et('All Sections'); ?> </td> <td class="listRow listRowOdd" style="text-align: center"> <select name="accessList[all][accessLevel]" style="width: 140px" onchange="(this.value=='1') ? $('.sectionAccessList').slideDown() : $('.sectionAccessList').slideUp();"> <option value="0" <?php selectedIf($allAccessLevel, '0'); ?> ><?php et('None'); ?> </option> <option value="3" <?php selectedIf($allAccessLevel, '3'); ?> ><?php et('Viewer'); ?> </option> <option value="6" <?php selectedIf($allAccessLevel, '6'); ?> ><?php et('Author'); ?> </option> <option value="7" <?php selectedIf($allAccessLevel, '7'); ?> ><?php eht('Author & Viewer'); ?> </option> <option value="9" <?php selectedIf($allAccessLevel, '9'); ?> ><?php et('Editor'); ?> </option> <option value="1" <?php selectedIf($allAccessLevel, '1'); ?> ><?php et('By Section'); ?> </option> </select> </td> <td class="listRow listRowOdd" style="text-align: center"><?php et('No Limit'); ?> </td> </tr> </table> <script type="text/javascript"> function toggleDisabledForAccessListMaxRecords(tablename) { var accessLevel = $("#accesslevel_"+tablename).val(); var disableMaxRecords = (accessLevel == 9 || accessLevel == 3); if (disableMaxRecords) { $("#maxRecords_"+tablename).attr("disabled", true).css("background-color","#DDD"); } else { $("#maxRecords_"+tablename).removeAttr("disabled").css("background-color","#FFF"); } } </script> <div class="sectionAccessList" style="<?php echo $sectionsDivStyle; ?> "> <div style="width: 0px; height: 0px;"></div><?php /* fixes IE7 issue which caused table to get no layout space, causing overlap and missing table content. the issue seems to be caused by a div with only a table inside. adding anything else inside the div seems to fix it, including  , but that adds extra whitespace, hence the div with no area */ ?> <table border="0" cellspacing="1" cellpadding="0"> <?php // list sections foreach ($sectionList as $section) { $bgColorClass = @$bgColorClass == "listRowEven" ? 'listRowOdd' : 'listRowEven'; # rotate bgclass $fieldnamePrefix = "accessList[{$section['tableName']}]"; $accessLevel = @$accessList[$section['tableName']]['accessLevel']; $maxRecords = @$accessList[$section['tableName']]['maxRecords']; $disableMaxRecords = $accessLevel == 9 || $accessLevel == 3; $maxRecordsAttr = $disableMaxRecords ? 'style="text-align: center; background-color: #DDD;" disabled="disabled"' : 'style="text-align: center;"'; ?> <tr> <td class="listRow <?php echo $bgColorClass; ?> " width="305"> <?php echo $section['menuName']; ?> </td> <td class="listRow <?php echo $bgColorClass; ?> " width="115" style="text-align: center"> <?php if ($section['menuType'] == 'single' || $section['tableName'] == 'accounts' || $section['menuType'] == 'menugroup' || $section['menuType'] == 'link') { ?> <input type="hidden" name="<?php echo $fieldnamePrefix; ?> [accessLevel]" value="0" /> <input type="checkbox" name="<?php echo $fieldnamePrefix; ?> [accessLevel]" value="9" <?php checkedIf($accessLevel, '9'); ?> /> <?php } elseif ($section['menuType'] == 'multi') { ?> <select name="<?php echo $fieldnamePrefix; ?> [accessLevel]" id="accesslevel_<?php echo $section['tableName']; ?> " style="width: 140px" onchange="toggleDisabledForAccessListMaxRecords('<?php echo $section['tableName']; ?> ')"> <option value="0" <?php selectedIf($accessLevel, '0'); ?> ><?php et('None'); ?> </option> <option value="3" <?php selectedIf($accessLevel, '3'); ?> ><?php et('Viewer'); ?> </option> <option value="6" <?php selectedIf($accessLevel, '6'); ?> ><?php et('Author'); ?> </option> <option value="7" <?php selectedIf($accessLevel, '7'); ?> ><?php eht('Author & Viewer'); ?> </option> <option value="9" <?php selectedIf($accessLevel, '9'); ?> ><?php et('Editor'); ?> </option> </select> <?php } elseif ($section['menuType'] == 'category') { ?> <select name="<?php echo $fieldnamePrefix; ?> [accessLevel]" id="accesslevel_<?php echo $section['tableName']; ?> " style="width: 140px" onchange="toggleDisabledForAccessListMaxRecords('<?php echo $section['tableName']; ?> ')"> <option value="0" <?php selectedIf($accessLevel, '0'); ?> ><?php et('None'); ?> </option> <option value="9" <?php selectedIf($accessLevel, '9'); ?> ><?php et('Editor'); ?> </option> </select> <?php } ?> </td> <td class="<?php echo $bgColorClass; ?> " width="100" style="text-align: center"> <?php if ($section['menuType'] == 'single') { printf(t("Single Page")); } elseif ($section['tableName'] == 'accounts') { ?> <?php } elseif ($section['menuType'] == 'multi') { ?> <input class="text-input medium-input" type="text" name="<?php echo $fieldnamePrefix; ?> [maxRecords]" id="maxRecords_<?php echo $section['tableName']; ?> " value="<?php echo $maxRecords; ?> " size="6" maxlength="6" <?php echo $maxRecordsAttr; ?> /> <?php } ?> </td> </tr> <?php } ?> </table></div> <br/><div style="font-size: 11px"> <b><?php et('Access Levels:'); ?> </b><br/> <div style="padding-left: 20px;"> <?php et('None - Don\'t allow user to access this section'); ?> <br/> <?php et('Viewer - User can view any record in this section (must also be enabled in section editor)'); ?> <br/> <?php et('Author - User can only access records they have created'); ?> <br/> <?php eht("Author & Viewer - User can view any record and modify records they've created"); ?> <br/> <?php et('Editor - User can access any records in this section'); ?> <br/> </div> <?php et('Max Records: Max records user is allowed to create (for regular users only - leave blank for unlimited)'); ?> </div> </td> </tr> <?php $html = ob_get_clean(); return $html; }
<tr> <td width="200"><?php et('Database Backup'); ?> </td> <td> <?php print sprintf(t('Create a backup file in %s of'), '/data/backups/'); ?> <select name="backupTable" id="backupTable"> <option value=''><?php et('all database tables'); ?> </option> <?php $schemaTables = getSchemaTables(); sort($schemaTables); echo getSelectOptions(@$_REQUEST['backupTable'], $schemaTables); ?> </select> <input class="button" type="button" name="null" value="<?php eht('Backup'); ?> " onclick="return redirectWithPost('?', {menu:'admin', action:'backup', 'backupTable':$('#backupTable').val(), '_CSRFToken': $('[name=_CSRFToken]').val()});" /><br/> </td> </tr> <tr> <td width="200"><?php et('Database Restore'); ?>
function backupDatabase($filenameOrPath = '', $selectedTable = '') { global $TABLE_PREFIX; $prefixPlaceholder = '#TABLE_PREFIX#_'; set_time_limit(60 * 5); // v2.51 - allow up to 5 minutes to backup/restore database session_write_close(); // v2.51 - End the current session and store session data so locked session data doesn't prevent concurrent access to CMS by user while backup in progress // error checking if ($selectedTable != '') { $schemaTables = getSchemaTables(); if (preg_match("/[^\\w\\d\\-\\.]/", $selectedTable)) { die(__FUNCTION__ . " : \$selectedTable contains invalid chars! " . htmlencode($selectedTable)); } if (!in_array($selectedTable, $schemaTables)) { die("Unknown table selected '" . htmlencode($selectedTable) . "'!"); } } // open backup file $hostname = preg_replace('/[^\\w\\d\\-\\.]/', '', @$_SERVER['HTTP_HOST']); if (!$filenameOrPath) { $filenameOrPath = "{$hostname}-v{$GLOBALS['APP']['version']}-" . date('Ymd-His'); if ($selectedTable) { $filenameOrPath .= "-{$selectedTable}"; } $filenameOrPath .= ".sql.php"; } $outputFilepath = isAbsPath($filenameOrPath) ? $filenameOrPath : DATA_DIR . "/backups/{$filenameOrPath}"; // v2.60 if only filename provided, use /data/backup/ as the basedir $fp = @fopen($outputFilepath, 'x'); if (!$fp) { // file already exists - avoid race condition session_start(); return false; } // create no execute php header fwrite($fp, "-- <?php die('This is not a program file.'); exit; ?>\n\n"); # prevent file from being executed // get tablenames to backup if ($selectedTable) { $tablenames = array(getTableNameWithPrefix($selectedTable)); } else { $skippedTables = array('_cron_log', '_error_log', '_outgoing_mail', '_nlb_log'); // don't backup these table names $skippedTables = applyFilters('backupDatabase_skippedTables', $skippedTables); // let users skip tables via plugins $skippedTables = array_map('getTableNameWithPrefix', $skippedTables); // add table_prefix to all table names (if needed) $allTables = getMysqlTablesWithPrefix(); $tablenames = array_diff($allTables, $skippedTables); // remove skipped tables from list } // backup database foreach ($tablenames as $unescapedTablename) { $escapedTablename = mysql_escape($unescapedTablename); $tablenameWithFakePrefix = $prefixPlaceholder . getTableNameWithoutPrefix($escapedTablename); // create table fwrite($fp, "\n--\n"); fwrite($fp, "-- Table structure for table `{$tablenameWithFakePrefix}`\n"); fwrite($fp, "--\n\n"); fwrite($fp, "DROP TABLE IF EXISTS `{$tablenameWithFakePrefix}`;\n\n"); $result = mysql_query("SHOW CREATE TABLE `{$escapedTablename}`"); list(, $createStatement) = mysql_fetch_row($result) or die("MySQL Error: " . htmlencode(mysql_error())); $createStatement = str_replace("TABLE `{$TABLE_PREFIX}", "TABLE `{$prefixPlaceholder}", $createStatement); fwrite($fp, "{$createStatement};\n\n"); if (is_resource($result)) { mysql_free_result($result); } // create rows fwrite($fp, "\n--\n"); fwrite($fp, "-- Dumping data for table `{$tablenameWithFakePrefix}`\n"); fwrite($fp, "--\n\n"); $result = mysql_query("SELECT * FROM `{$escapedTablename}`") or die("MySQL Error: " . htmlencode(mysql_error())); while ($row = mysql_fetch_row($result)) { $values = ''; foreach ($row as $value) { if (is_null($value)) { $values .= 'NULL,'; } else { $values .= '"' . mysql_real_escape_string($value) . '",'; } } $values = chop($values, ','); // remove trailing comma fwrite($fp, "INSERT INTO `{$tablenameWithFakePrefix}` VALUES({$values});\n"); } if (is_resource($result)) { mysql_free_result($result); } } // fwrite($fp, "\n"); $result = fwrite($fp, "-- Dump completed on " . date('Y-m-d H:i:s O') . "\n\n"); if ($result === false) { die(__FUNCTION__ . ": Error writing backup file! {$php_errormsg}"); } fclose($fp) || die(__FUNCTION__ . ": Error closing backup file! {$php_errormsg}"); // @session_start(); // hide error: E_WARNING: session_start(): Cannot send session cache limiter - headers already sent return $outputFilepath; }