Example #1
0
 function commit()
 {
     global $db, $config_vars;
     // check if allowed
     if (true) {
         if (!isset($this->id)) {
             // this is object is not yet in the datebase, make a new entry
             $sql = 'INSERT INTO ' . $config_vars['table_prefix'] . "content_meta_fields (fieldname)\n\t\t\t\t\tVALUES ('" . database_encode($this->fieldname) . "')";
             if (!($result = $db->sql_query($sql))) {
                 error_report(SQL_ERROR, 'commit', __LINE__, __FILE__, $sql);
             }
             // set id;
             $this->id = $db->sql_nextid();
             return OP_SUCCESSFULL;
         } else {
             // object is already in the database just du an update
             $sql = 'UPDATE ' . $config_vars['table_prefix'] . "content_meta_fields\n\t\t\t\t\tSET \tfieldname = '" . database_encode($this->fieldname) . "'\n\t\t\t\t\tWHERE id = {$this->id}";
             if (!($result = $db->sql_query($sql))) {
                 error_report(SQL_ERROR, 'commit', __LINE__, __FILE__, $sql);
             }
             return OP_SUCCESSFULL;
         }
     }
     return OP_NP_MISSING_EDIT;
 }
 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;
     }
 }
 function commit()
 {
     //commits all changes of the actual object to the database and/or filesystem
     //or create a new db entry if object is not yet in db
     global $db, $config_vars;
     // fill palce_in_cat and cat_ids array if they are not yet filled;
     if (isset($this->id)) {
         if (!isset($this->cat_ids) or !isset($this->place_in_cat)) {
             $this->generate_content_in_cat_data();
         }
     }
     // if content is in no cat anymore
     if (sizeof($this->cat_ids) == 0) {
         // move content in the deleted pics cat.
         $del_content_cat = new categorie();
         $del_content_cat->generate_from_id($config_vars['deleted_content_cat']);
         $del_content_cat->content_amount++;
         $this->cat_ids[0] = $config_vars['deleted_content_cat'];
         $this->new_filename = $this->generate_filename();
     }
     // move to the new calculated localtaion (may be the same)
     if (isset($this->new_filename)) {
         if (!is_dir(dirname($this->new_filename))) {
             makedir(dirname($this->new_filename));
         }
         // echo "rename({$this->file},$new_file)<br>";
         if (rename($this->file, $this->new_filename)) {
             $this->set_file($this->new_filename);
         } else {
             die('content rename failed ' . $this->file . ' to ' . $this->new_filename);
         }
         //echo "rename pic" .$this->file." -> ".$new_file."<br>";
         // move thumb
         if (!is_dir(dirname($this->get_thumbfile()))) {
             makedir(dirname($this->get_thumbfile()));
         }
     }
     //echo "rename thumb" .$this->thumbfile." -> ".$this->get_thumbfile()."<br>";
     // but first check if thumb exists
     //echo "rename({/*$this->thumbfile*/},".$this->get_thumbfile().")<br>";
     if (is_file($this->thumbfile)) {
         if (rename($this->thumbfile, $this->get_thumbfile())) {
             $this->thumbfile = $this->get_thumbfile();
         } else {
             die('thumb rename failed');
         }
     }
     // check if already in db)
     if (isset($this->id)) {
         // already in db
         // update entry in content table
         $sql = "UPDATE " . $config_vars['table_prefix'] . "content\n\t\t\t\tSET\n\t\t\t\t\tfile = '{$this->file}',\n\t\t\t\t\tname = '" . database_encode($this->name) . "',\n\t\t\t\t\tviews = '{$this->views}',\n\t\t\t\t\tcurrent_rating = '{$this->current_rating}',\n\t\t\t\t\tcreation_date = '{$this->creation_date}',\n\t\t\t\t\tcontentgroup_id = '{$this->contentgroup_id}',\n\t\t\t\t\tlocked = '{$this->locked}',\n\t\t\t\t\twidth = '{$this->width}',\n\t\t\t\t\theight = '{$this->height}',\n\t\t\t\t\tcomments_amount = '{$this->comments_amount}'\n\t\t\t\tWHERE id = {$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, 'commit' , __LINE__, __FILE__,$sql);
         }
         // update content_in_cat table
         // i will do this by first deleting all entry with this content and then generate them all new
         $this->clear_content_in_cat();
     } else {
         $this->calc_size();
         //not in db
         $this->creation_date = date("Y-m-d H:i:s");
         // add content to the content table
         //using a shorter version of boolean transmission for locked
         $sql = "INSERT INTO " . $config_vars['table_prefix'] . "content\n\t\t\t\t(file,name,views,current_rating,creation_date,contentgroup_id,locked,width,height,comments_amount)\n\t\t\t\tVALUES ('{$this->file}', '" . database_encode($this->name) . "', '{$this->views}', '{$this->current_rating}', '{$this->creation_date}', '{$this->contentgroup_id}', '" . ($this->locked ? '1' : '0') . "','{$this->width}','{$this->height}','{$this->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);
         }
         // set id of object to the id of the insert
         $this->id = $db->sql_nextid();
     }
     // add content to the cats
     $this->fill_content_in_cat();
     if (is_object($del_content_cat)) {
         $del_content_cat->commit();
     }
     if (is_object($this->add_to_cat)) {
         $this->add_to_cat->commit();
     }
     if (is_object($this->remove_from_cat)) {
         $this->remove_from_cat->commit();
     }
     if (is_array($this->commit_parent_cats)) {
         foreach ($this->commit_parent_cats as $parent_cat) {
             $parent_cat->commit();
         }
     }
     return OP_SUCESSFUL;
 }
 function commit()
 {
     global $db, $config_vars;
     if (!isset($this->id)) {
         $this->creation_date = date("Y-m-d H:i:s");
         // this is object is not yet in the datebase, make a new entry
         $sql = 'INSERT INTO ' . $config_vars['table_prefix'] . get_class($this) . "s \n\t\t\t\t(owner_id, feedback, user_id, creation_date, changed_count, parent_id, topic, last_changed_date, poster_name)\n\t\t\t\tVALUES ('{$this->owner_id}', '" . database_encode($this->feedback) . "', '{$this->user_id}', '{$this->creation_date}', '{$this->changed_count}', '{$this->parent_id}', '" . database_encode($this->topic) . "', '{$this->last_changed_date}', '" . database_encode($this->poster_name) . "')";
         if (!($result = $db->sql_query($sql))) {
             error_report(SQL_ERROR, 'commit', __LINE__, __FILE__, $sql);
         }
         return OP_SUCCESSFULL;
         // set id;
         $this->id = $db->sql_nextid();
         // TODO: update child_comments of cats
     } else {
         // object is already in the database just du an update
         $sql = 'UPDATE ' . $config_vars['table_prefix'] . get_class($this) . "s  \n\t\t\t\tSET\towner_id = '{$this->owner_id}',\n\t\t\t\t\tfeedback = '" . database_encode($this->feedback) . "',\n\t\t\t\t\tuser_id = '{$this->user_id}',\n\t\t\t\t\tcreation_date = '{$this->creation_date}',\n\t\t\t\t\tchanged_count = '{$this->changed_count}', \n\t\t\t\t\tparent_id = '{$this->parent_id}', \n\t\t\t\t\ttopic = '" . database_encode($this->topic) . "',\n\t\t\t\t\tlast_changed_date = '{$this->last_changed_date}',\n\t\t\t\t\tposter_name = '" . database_encode($this->poster_name) . "'\n\t\t\t\tWHERE id like {$this->id}";
         if (!($result = $db->sql_query($sql))) {
             error_report(SQL_ERROR, 'commit', __LINE__, __FILE__, $sql);
         }
         return OP_SUCCESSFULL;
     }
 }