Пример #1
0
 function __construct()
 {
     global $_zp_authority, $_userAddressFields;
     $firstTime = false;
     $tablecols = db_list_fields('administrators');
     foreach ($tablecols as $key => $datum) {
         if ($datum['Field'] == 'custom_data') {
             $firstTime = true;
             enableExtension('userAddressFields', true);
             break;
         }
     }
     parent::constructor('userAddressFields', self::fields());
     if ($firstTime) {
         //	migrate the custom data user data
         $result = query('SELECT * FROM ' . prefix('administrators') . ' WHERE `valid`!=0');
         if ($result) {
             while ($row = db_fetch_assoc($result)) {
                 $custom = getSerializedArray($row['custom_data']);
                 if (!empty($custom)) {
                     $sql = 'UPDATE ' . prefix('administrators') . ' SET ';
                     foreach ($custom as $field => $val) {
                         $sql .= '`' . $field . '`=' . db_quote($val) . ',';
                     }
                     setupQuery($sql);
                 }
             }
             db_free_result($result);
         }
         setupQuery('ALTER TABLE ' . prefix('administrators') . ' DROP `custom_data`');
     }
     $cloneid = bin2hex(FULLWEBPATH);
     if (OFFSET_PATH == 2 && isset($_SESSION['admin'][$cloneid])) {
         $user = unserialize($_SESSION['admin'][$cloneid]);
         $user2 = $_zp_authority->getAnAdmin(array('`user`=' => $user->getUser(), '`pass`=' => $user->getPass(), '`valid`=' => 1));
         if ($user2) {
             foreach (userAddressFields::fields() as $field) {
                 $user2->set($field['name'], $user->get($field['name']));
             }
             $user2->save();
         }
     }
 }
Пример #2
0
                if ($indexComments) {
                    $tableString .= "  COMMENT 'zp20'";
                }
                $create[] = $tableString . ',';
            }
            unset($database[$tablename]['keys'][$key]);
        }
    }
    if (!$exists) {
        $create[] = "  PRIMARY KEY (`id`)";
        $create[] = ") {$collation};";
        $create = implode("\n", $create);
        setupQuery($create);
    } else {
        //handle surplus fields
        if (array_key_exists('keys', $database[$tablename]) && !empty($database[$tablename]['keys'])) {
            foreach ($database[$tablename]['keys'] as $index) {
                $key = $index['Key_name'];
                if (isset($index['Index_comment']) && $index['Index_comment'] === 'zp20') {
                    $dropString = "ALTER TABLE " . prefix($tablename) . " DROP INDEX `" . $key . "`;";
                    setupQuery($dropString);
                } else {
                    $orpahns = sprintf(gettext('Setup found the key "%1$s" in the "%2$s" table. This index is not in use by ZenPhoto20.'), $key, $tablename);
                }
            }
        }
    }
}
foreach ($orphans as $message) {
    setupLog($message, true);
}
Пример #3
0
 /**
  *
  * This method establishes the current set of database fields. It will add the
  * fields to the database if they are not already present. Fields from previous
  * constructor calls that are no longer in the list will be removed from the
  * database (along with any data associated with them.)
  *
  * @param array $newfields
  */
 function constructor($me, $newfields)
 {
     $database = array();
     foreach (getDBTables() as $table) {
         $tablecols = db_list_fields($table);
         foreach ($tablecols as $key => $datum) {
             $database[$table][$datum['Field']] = $datum;
         }
     }
     $current = $fields = $searchDefault = array();
     if (extensionEnabled($me)) {
         //need to update the database tables.
         foreach ($newfields as $newfield) {
             $table = $newfield['table'];
             $name = $newfield['name'];
             if (!($existng = isset($database[$table][$name]))) {
                 if (isset($newfield['searchDefault']) && $newfield['searchDefault']) {
                     $searchDefault[] = $name;
                 }
             }
             if (is_null($newfield['type'])) {
                 if ($name == 'tags') {
                     setOption('adminTagsTab', 1);
                 }
             } else {
                 switch (strtolower($newfield['type'])) {
                     default:
                         $dbType = strtoupper($newfield['type']);
                         break;
                     case 'int':
                         $dbType = strtoupper($newfield['type']) . '(' . min(255, $newfield['size']) . ')';
                         if (isset($newfield['attribute'])) {
                             $dbType .= ' ' . $newfield['attribute'];
                             unset($newfield['attribute']);
                         }
                         break;
                     case 'varchar':
                         $dbType = strtoupper($newfield['type']) . '(' . min(255, $newfield['size']) . ')';
                         break;
                 }
                 if ($existng) {
                     if (strtoupper($database[$table][$name]['Type']) != $dbType || empty($database[$table][$name]['Comment'])) {
                         $cmd = ' CHANGE `' . $name . '`';
                     } else {
                         $cmd = NULL;
                     }
                     unset($database[$table][$name]);
                 } else {
                     $cmd = ' ADD COLUMN';
                 }
                 $sql = 'ALTER TABLE ' . prefix($newfield['table']) . $cmd . ' `' . $name . '` ' . $dbType;
                 if (isset($newfield['attribute'])) {
                     $sql .= ' ' . $newfield['attribute'];
                 }
                 if (isset($newfield['default'])) {
                     $sql .= ' DEFAULT ' . $newfield['default'];
                 }
                 $sql .= " COMMENT 'optional_{$me}'";
                 if ((!$cmd || setupQuery($sql)) && in_array($newfield['table'], array('albums', 'images', 'news', 'news_categories', 'pages'))) {
                     $fields[] = strtolower($newfield['name']);
                 }
                 $current[$newfield['table']][$newfield['name']] = $dbType;
             }
         }
         setOption(get_class($this) . '_addedFields', serialize($current));
         if (!empty($searchDefault)) {
             $fieldExtenderMutex = new zpMutex('fE');
             $fieldExtenderMutex->lock();
             $engine = new SearchEngine();
             $set_fields = $engine->allowedSearchFields();
             $set_fields = array_unique(array_merge($set_fields, $searchDefault));
             setOption('search_fields', implode(',', $set_fields));
             $fieldExtenderMutex->unlock();
         }
     } else {
         purgeOption(get_class($this) . '_addedFields');
     }
     foreach ($database as $table => $fields) {
         //drop fields no longer defined
         foreach ($fields as $field => $orphaned) {
             if ($orphaned['Comment'] == "optional_{$me}") {
                 $sql = 'ALTER TABLE ' . prefix($table) . ' DROP `' . $field . '`';
                 setupQuery($sql);
             }
         }
     }
 }
Пример #4
0
 function __construct()
 {
     if (OFFSET_PATH == 2) {
         $present = array('albums' => 0, 'images' => 0, 'news' => 0, 'pages' => 0, 'news_categories' => 0);
         foreach ($present as $table => $v) {
             $tablecols = db_list_fields($table);
             foreach ($tablecols as $key => $datum) {
                 if ($datum['Field'] == 'custom_data') {
                     $present[$table] = 1 + (int) (!empty($datum['Comment']));
                 }
             }
         }
         if (extensionEnabled('customdata')) {
             setOptionDefault('customDataAlbums', $present['albums']);
             setOptionDefault('customDataImages', $present['images']);
             setOptionDefault('customDataNews', $present['news']);
             setOptionDefault('customDataPages', $present['pages']);
             setOptionDefault('customDataCategories', $present['news_categories']);
         } else {
             purgeOption('customDataAlbums');
             purgeOption('customDataImages');
             purgeOption('customDataNews');
             purgeOption('customDataPages');
             purgeOption('customDataCategories');
         }
         if (getOption('customDataAlbums')) {
             if (!$present['albums']) {
                 setupQuery('ALTER TABLE ' . prefix('albums') . " ADD COLUMN `custom_data` TEXT COMMENT 'optional_customData'");
             }
         } else {
             if ($present['albums']) {
                 setupQuery('ALTER TABLE ' . prefix('albums') . ' DROP `custom_data`');
             }
         }
         if (getOption('customDataImages')) {
             if (!$present['images']) {
                 setupQuery('ALTER TABLE ' . prefix('images') . " ADD COLUMN `custom_data` TEXT COMMENT 'optional_customData'");
             }
         } else {
             if ($present['images']) {
                 setupQuery('ALTER TABLE ' . prefix('images') . ' DROP `custom_data`');
             }
         }
         if (getOption('customDataNews')) {
             if (!$present['news']) {
                 setupQuery('ALTER TABLE ' . prefix('news') . " ADD COLUMN `custom_data` TEXT COMMENT 'optional_customData'");
             }
         } else {
             if ($present['news']) {
                 setupQuery('ALTER TABLE ' . prefix('news') . ' DROP `custom_data`');
             }
         }
         if (getOption('customDataPages')) {
             if (!$present['pages']) {
                 setupQuery('ALTER TABLE ' . prefix('pages') . " ADD COLUMN `custom_data` TEXT COMMENT 'optional_customData'");
             }
         } else {
             if ($present['pages']) {
                 setupQuery('ALTER TABLE ' . prefix('pages') . ' DROP `custom_data`');
             }
         }
         if (getOption('customDataCategories')) {
             if (!$present['news_categories']) {
                 setupQuery('ALTER TABLE ' . prefix('news_categories') . " ADD COLUMN `custom_data` TEXT COMMENT 'optional_customData'");
             }
         } else {
             if ($present['news_categories']) {
                 setupQuery('ALTER TABLE ' . prefix('news_categories') . ' DROP `custom_data`');
             }
         }
     }
 }
Пример #5
0
function showWines($connection, &$template)
{
    // Produce a heading for the top of the page
    $template->setCurrentBlock();
    $template->setVariable("SEARCHCRITERIA", "Region: {$_SESSION["searchFormVars"]["region_name"]} " . "Wine type: {$_SESSION["searchFormVars"]["wine_type"]}");
    // Encode the search parameters for embedding in links to other pages
    // of results
    $browseString = "wine_type=" . urlencode($_SESSION["searchFormVars"]["wine_type"]) . "&region_name=" . urlencode($_SESSION["searchFormVars"]["region_name"]);
    // Build the query using the search criteria
    $query = setupQuery($_SESSION["searchFormVars"]["region_name"], $_SESSION["searchFormVars"]["wine_type"]);
    $result = $connection->query($query);
    if (DB::isError($result)) {
        trigger_error($result->getMessage(), E_USER_ERROR);
    }
    $numRows = $result->numRows();
    // Is there any data?
    if ($numRows > 0) {
        // Yes, there is data.
        // Check that the offset is sensible and, if not, fix it.
        // Offset greater than the number of rows?
        // Set it to the number of rows LESS SEARCH_ROWS
        if ($_SESSION["searchFormVars"]["offset"] > $numRows) {
            $_SESSION["searchFormVars"]["offset"] = $numRows - SEARCH_ROWS;
        }
        // Offset less than zero? Set it to zero
        if ($_SESSION["searchFormVars"]["offset"] < 0) {
            $_SESSION["searchFormVars"]["offset"] = 0;
        }
        // The "Previous" page begins at the current
        // offset LESS the number of SEARCH_ROWS per page
        $previousOffset = $_SESSION["searchFormVars"]["offset"] - SEARCH_ROWS;
        // The "Next" page begins at the current offset
        // PLUS the number of SEARCH_ROWS per page
        $nextOffset = $_SESSION["searchFormVars"]["offset"] + SEARCH_ROWS;
        // Fetch one page of results (or less if on the
        // last page, starting at $_SESSION["searchFormVars"]["offset"])
        for ($rowCounter = 0; $rowCounter < SEARCH_ROWS && $rowCounter + $_SESSION["searchFormVars"]["offset"] < $result->numRows() && ($row = $result->fetchRow(DB_FETCHMODE_ASSOC, $_SESSION["searchFormVars"]["offset"] + $rowCounter)); $rowCounter++) {
            $template->setCurrentBlock("row");
            $template->setVariable("YEAR", $row["year"]);
            $template->setVariable("WINERY", $row["winery_name"]);
            $template->setVariable("WINE", $row["wine_name"]);
            $template->setVariable("VARIETIES", showVarieties($connection, $row["wine_id"]));
            $price = showPricing($connection, $row["wine_id"]);
            $template->setVariable("BOTTLE_PRICE", sprintf("\$%4.2f", $price));
            $template->setVariable("DOZEN_PRICE", sprintf("\$%4.2f", $price * 12));
            $template->setVariable("ONEHREF", S_ADDTOCART . "?qty=1&amp;wineId={$row["wine_id"]}");
            $template->setVariable("DOZENHREF", S_ADDTOCART . "?qty=12&amp;wineId={$row["wine_id"]}");
            $template->parseCurrentBlock("row");
        }
        // end for rows in the page
        // Show the row numbers that are being viewed
        $template->setCurrentBlock();
        $template->setVariable("BEGINROW", $_SESSION["searchFormVars"]["offset"] + 1);
        $template->setVariable("ENDROW", $rowCounter + $_SESSION["searchFormVars"]["offset"]);
        $template->setVariable("ROWS", $result->numRows());
        // Are there any previous pages?
        if ($_SESSION["searchFormVars"]["offset"] >= SEARCH_ROWS) {
            // Yes, so create a previous link
            $template->setCurrentBlock("link");
            $template->setVariable("HREF", S_SEARCH . "?offset=" . rawurlencode($previousOffset) . "&amp;{$browseString}");
            $template->setVariable("HREFTEXT", "Previous");
            $template->parseCurrentBlock("link");
        } else {
            // No, there is no previous page so don't
            // print a link
            $template->setCurrentBlock("outtext");
            $template->setVariable("OUTTEXT", "Previous");
            $template->parseCurrentBlock("outtext");
        }
        $template->setCurrentBlock("links");
        $template->parseCurrentBlock("links");
        // Output the page numbers as links
        // Count through the number of pages in the results
        for ($x = 0, $page = 1; $x < $result->numRows(); $x += SEARCH_ROWS, $page++) {
            // Is this the current page?
            if ($x < $_SESSION["searchFormVars"]["offset"] || $x > $_SESSION["searchFormVars"]["offset"] + SEARCH_ROWS - 1) {
                // No, so print a link to that page
                $template->setCurrentBlock("link");
                $template->setVariable("HREF", S_SEARCH . "?offset=" . rawurlencode($x) . "&amp;{$browseString}");
                $template->setVariable("HREFTEXT", $page);
                $template->parseCurrentBlock("link");
            } else {
                // Yes, so don't print a link
                $template->setCurrentBlock("outtext");
                $template->setVariable("OUTTEXT", $page);
                $template->parseCurrentBlock("outtext");
            }
            $template->setCurrentBlock("links");
            $template->parseCurrentBlock("links");
        }
        // Are there any Next pages?
        if (isset($row) && $result->numRows() > $nextOffset) {
            // Yes, so create a next link
            $template->setCurrentBlock("link");
            $template->setVariable("HREF", S_SEARCH . "?offset=" . rawurlencode($nextOffset) . "&amp;{$browseString}");
            $template->setVariable("HREFTEXT", "Next");
            $template->parseCurrentBlock("link");
        } else {
            // No, there is no next page so don't
            // print a link
            $template->setCurrentBlock("outtext");
            $template->setVariable("OUTTEXT", "Next");
            $template->parseCurrentBlock("outtext");
        }
        $template->setCurrentBlock("links");
        $template->parseCurrentBlock("links");
    } else {
        $template->setCurrentBlock("outtext");
        $template->setVariable("OUTTEXT", "No wines found matching your criteria.");
        $template->parseCurrentBlock("outtext");
        $template->setCurrentBlock("links");
        $template->parseCurrentBlock("links");
    }
}