} $result = cpg_db_query("SELECT parent FROM {$CONFIG['TABLE_CATEGORIES']} WHERE cid = {$cid}"); if (!$result->numRows()) { cpg_die(ERROR, $lang_catmgr_php['unknown_cat'], __FILE__, __LINE__); } $del_category = $result->fetchAssoc(true); $parent = $del_category['parent']; cpg_db_query("UPDATE {$CONFIG['TABLE_CATEGORIES']} SET parent = {$parent}, lft = 0 WHERE parent = {$cid}"); cpg_db_query("UPDATE {$CONFIG['TABLE_ALBUMS']} SET category = {$parent} WHERE category = {$cid}"); cpg_db_query("DELETE FROM {$CONFIG['TABLE_CATEGORIES']} WHERE cid = {$cid}"); //delete from categorymap cpg_db_query("DELETE FROM {$CONFIG['TABLE_CATMAP']} WHERE cid = {$cid}"); break; } if ($op) { check_rebuild_tree(); } get_subcat_data(0); pageheader($lang_catmgr_php['manage_cat']); starttable('100%', cpg_fetch_icon('cat_mgr', 2) . $lang_catmgr_php['category'] . ' ' . cpg_display_help('f=categories.htm&as=cat_cp&ae=cat_cp_end&top=1', '800', '600'), 1); echo <<<EOT <tr> <td class="tableb"> EOT; starttable('100%'); // configure sort category alphabetically $yes_selected = $CONFIG['categories_alpha_sort'] ? 'checked="checked"' : ''; $no_selected = !$CONFIG['categories_alpha_sort'] ? 'checked="checked"' : ''; $help = ' ' . cpg_display_help('f=configuration.htm&as=admin_album_list_alphasort_start&ae=admin_album_list_alphasort_end&top=1', '600', '250'); echo <<<EOT <tr>
function update_tables() { global $errors, $CONFIG, $lang_update_php, $lang_common, $LINEBREAK, $help; global $update_icon, $ok_icon, $already_done_icon, $error_icon, $file_system_icon; $loopCounter = 0; $cellStyle = ''; $superCage = Inspekt::makeSuperCage(); $db_update = 'sql/update.sql'; $sql_query = fread(fopen($db_update, 'r'), filesize($db_update)); // Update table prefix $sql_query = preg_replace('/CPG_/', $CONFIG['TABLE_PREFIX'], $sql_query); $sql_query = remove_remarks($sql_query); $sql_query = split_sql_file($sql_query, ';'); $sql_query = array_map('trim', $sql_query); echo <<<EOT <tr> <td class="tableh1" colspan="2"> {$update_icon}{$lang_update_php['performing_database_updates']}{$help} </td> </tr> EOT; foreach ($sql_query as $q) { $cellStyle = $loopCounter / 2 == floor($loopCounter / 2) ? 'tableb' : 'tableb tableb_alternate'; $loopCounter++; echo '<tr>' . $LINEBREAK . ' <td width="80%" class="' . $cellStyle . '">' . $q; /** * Determining if the Alter Table actually made a change * to properly reflect it's status on the update page. */ if (strpos(strtolower($q), 'alter table') !== false) { $query = explode(' ', $q); $result = mysql_query("DESCRIBE " . $query[2]); $description = array(); while ($row = mysql_fetch_row($result)) { $description[] = $row; } $result = @mysql_query($q); $affected = mysql_affected_rows(); $warnings = mysql_query('SHOW WARNINGS'); $result = mysql_query("DESCRIBE " . $query[2]); $description2 = array(); while ($row = mysql_fetch_row($result)) { $description2[] = $row; } if ($description == $description2) { $affected = 0; } } else { $result = @mysql_query($q); $affected = mysql_affected_rows(); $warnings = mysql_query('SHOW WARNINGS;'); } if ($superCage->get->keyExists('debug')) { echo '<hr />Debug output:<br />'; if ($affected > -1) { echo "Rows Affected: " . $affected . ". "; } if ($warnings) { while ($warning = mysql_fetch_row($warnings)) { if ($warning[0] != '') { $warning_text = 'MySQL said: '; } else { $warning_text = ''; } echo $warning_text . '<tt class="code">' . $warning[0] . ' (' . $warning[1] . ') ' . $warning[2] . '</tt><br />'; } } } echo '</td>' . $LINEBREAK; // end the table cell that contains the output if ($result && $affected) { echo ' <td width="20%" class="' . $cellStyle . ' updatesOK">' . $ok_icon . $lang_common['ok'] . '</td>' . $LINEBREAK; } else { echo ' <td width="20%" class="' . $cellStyle . ' updatesFail">' . $already_done_icon . $lang_update_php['already_done'] . '</td>' . $LINEBREAK; } echo '</tr>' . $LINEBREAK; } // end foreach loop // Check password encryption and perform the conversion if applicable $cellStyle = $loopCounter / 2 == floor($loopCounter / 2) ? 'tableb' : 'tableb tableb_alternate'; $loopCounter++; echo <<<EOT <tr> <td class="{$cellStyle}"> {$lang_update_php['password_encryption']}: </td> EOT; $CONFIG['enable_encrypted_passwords'] = cpg_get_config_value('enable_encrypted_passwords'); if ($CONFIG['enable_encrypted_passwords'] != '1') { echo <<<EOT <td class="{$cellStyle} updatesOK"> {$ok_icon}{$lang_common['ok']} </td> </tr> EOT; $result = mysql_query("update {$CONFIG['TABLE_PREFIX']}users set user_password=md5(user_password);"); if ($CONFIG['enable_encrypted_passwords'] === '0') { $result = mysql_query("update {$CONFIG['TABLE_PREFIX']}config set value = '1' WHERE name = 'enable_encrypted_passwords'"); } else { $result = mysql_query("INSERT INTO {$CONFIG['TABLE_PREFIX']}config ( `name` , `value` ) VALUES ('enable_encrypted_passwords', '1')"); } } else { echo <<<EOT <td class="{$cellStyle} updatesFail"> {$already_done_icon}{$lang_update_php['already_done']} </td> </tr> EOT; } // Check album password encryption and perform the conversion if applicable $cellStyle = $loopCounter / 2 == floor($loopCounter / 2) ? 'tableb' : 'tableb tableb_alternate'; $loopCounter++; echo <<<EOT <tr> <td class="{$cellStyle}"> {$lang_update_php['alb_password_encryption']}: </td> EOT; $CONFIG['enable_encrypted_alb_passwords'] = cpg_get_config_value('enable_encrypted_alb_passwords'); if ($CONFIG['enable_encrypted_alb_passwords'] != 1) { echo <<<EOT <td class="{$cellStyle} updatesOK"> {$ok_icon}{$lang_common['ok']} </td> </tr> EOT; // Encrypt the album password but only for those albums which have a password assigned. $result = mysql_query("update {$CONFIG['TABLE_PREFIX']}albums set alb_password=md5(alb_password) WHERE alb_password IS NOT NULL AND alb_password != '';"); if ($CONFIG['enable_encrypted_alb_passwords'] != NULL) { $result = mysql_query("update {$CONFIG['TABLE_PREFIX']}config set value = 1 WHERE name = 'enable_encrypted_alb_passwords'"); } else { $result = mysql_query("INSERT INTO {$CONFIG['TABLE_PREFIX']}config ( `name` , `value` ) VALUES ('enable_encrypted_alb_passwords', '1')"); } } else { echo <<<EOT <td class="{$cellStyle} updatesFail"> {$already_done_icon}{$lang_update_php['already_done']} </td> </tr> EOT; } // Check category tree modifications $cellStyle = $loopCounter / 2 == floor($loopCounter / 2) ? 'tableb' : 'tableb tableb_alternate'; $loopCounter++; echo <<<EOT <tr> <td class="{$cellStyle}"> {$lang_update_php['category_tree']}: </td> EOT; if (check_rebuild_tree()) { echo <<<EOT <td class="{$cellStyle} updatesOK"> {$ok_icon}{$lang_common['ok']} </td> </tr> EOT; } else { echo <<<EOT <td class="{$cellStyle} updatesFail"> {$already_done_icon}{$lang_update_php['already_done']} </td> </tr> EOT; } }