Пример #1
0
 function commit()
 {
     //if the object is already in the db it is updated by the changes made to this object, otherwise a new db entry is made
     global $db, $config_vars;
     if (!isset($this->id)) {
         if ($this->is_serie === false) {
             $is_serie = 0;
         } else {
             $is_serie = 1;
         }
         // this is object is not yet in the datebase, make a new entry
         $sql = 'INSERT INTO ' . $config_vars['table_prefix'] . "cats (name, current_rating, parent_id, catgroup_id,is_serie,content_amount,description,child_content_amount,child_comments_amount)\n\t\t\t\tVALUES ('" . database_encode($this->name) . "', '{$this->current_rating}', '{$this->parent_id}', '{$this->catgroup_id}', '{$is_serie}', '{$this->content_amount}', '" . database_encode($this->description) . "', '{$this->child_content_amount}', '{$this->child_comments_amount}')";
         if (!($result = $db->sql_query($sql))) {
             $error = new phreak_error(E_WARNING, SQL_ERROR, __LINE__, __FILE__, 'commit', $this->id, 0, 0, $sql);
             $error->commit();
             // 				error_report(SQL_ERROR, 'commit' , __LINE__, __FILE__,$sql);
         }
         $this->id = $db->sql_nextid();
         return OP_SUCCESSFUL;
     } else {
         // object is already in the database just du an update
         $sql = 'UPDATE ' . $config_vars['table_prefix'] . "cats \n\t\t\t\tSET \tname = '" . database_encode($this->name) . "',\n\t\t\t\t\tcurrent_rating = '{$this->current_rating}', \n\t\t\t\t\tparent_id = '{$this->parent_id}', \n\t\t\t\t\tcatgroup_id = '{$this->catgroup_id}',\n\t\t\t\t\tis_serie = '{$this->is_serie}',\n\t\t\t\t\tcontent_amount = '{$this->content_amount}',\n\t\t\t\t\tdescription = '" . database_encode($this->description) . "',\n\t\t\t\t\tchild_content_amount = '{$this->child_content_amount}',\n\t\t\t\t\tchild_comments_amount = '{$this->child_comments_amount}'\n\t\t\t\tWHERE id like {$this->id}";
         if (!($result = $db->sql_query($sql))) {
             $error = new phreak_error(E_WARNING, SQL_ERROR, __LINE__, __FILE__, 'commit', $this->id, 0, 0, $sql);
             $error->commit();
             // 				error_report(SQL_ERROR, 'commmit' , __LINE__, __FILE__,$sql);
         }
         // recalc child content_amount
         if ($this->get_id() != $config_vars['root_categorie']) {
             $cat = new categorie();
             $cat->generate_from_id($this->get_parent_id());
             $cat->set_child_content_amount($cat->calc_child_content_amount());
             $cat->commit();
         }
         if (isset($this->commit_parent_cat)) {
             $this->commit_parent_cat->commit();
         }
         return OP_SUCCESSFUL;
     }
 }
Пример #2
0
define('CONTENT_IN_CAT_AMOUNT', 1);
define('CHILD_CONTENT_IN_CAT_AMOUNT', 2);
define('CHILD_COMMENTS_IN_CAT_AMOUNT', 3);
define('CONTENT_COMMENTS_AMOUNT', 4);
if (isset($HTTP_POST_VARS['do_correct'])) {
    if (is_array($HTTP_POST_VARS['correct'])) {
        foreach ($HTTP_POST_VARS['correct'] as $key => $value) {
            if ($HTTP_POST_VARS['type'][$key] == CONTENT_IN_CAT_AMOUNT) {
                $cat = new categorie();
                $cat->generate_from_id($HTTP_POST_VARS['id'][$key]);
                $cat->set_content_amount($cat->calc_content_amount());
                $cat->commit();
            } elseif ($HTTP_POST_VARS['type'][$key] == CHILD_CONTENT_IN_CAT_AMOUNT) {
                $cat = new categorie();
                $cat->generate_from_id($HTTP_POST_VARS['id'][$key]);
                $cat->set_child_content_amount($cat->calc_child_content_amount());
                $cat->commit();
            } elseif ($HTTP_POST_VARS['type'][$key] == CHILD_COMMENTS_IN_CAT_AMOUNT) {
                $cat = new categorie();
                $cat->generate_from_id($HTTP_POST_VARS['id'][$key]);
                $cat->set_child_comments_amount($cat->calc_child_comments_amount());
                $cat->commit();
            } elseif ($HTTP_POST_VARS['type'][$key] == CONTENT_COMMENTS_AMOUNT) {
                $content = get_content_object_from_id($HTTP_POST_VARS['id'][$key]);
                $content->set_comments_amount($content->calc_comments_amount());
                $content->commit();
            }
        }
    }
}
// check content amount for each cat