function category_restore($id, $param=array()) { global $db_central; global $current_user; if(!isset($param['version'])) return false; $cat=new category($id); $newest=$cat->get_newest_version(); $pg_id=postgre_escape($id); $pg_version=postgre_escape($param['version']); $pg_newest=postgre_escape($newest); $future=uniqid(); $pg_future=postgre_escape($future); // compile version tags $version_tags=new tags(); $version_tags->set("user", $current_user->username); $version_tags->set("date", Date("c")); $version_tags->set("msg", "Restore version '{$param['version']}'"); $pg_version_tags=array_to_hstore($version_tags->data()); $sql ="begin;"; $sql.="insert into category (select $pg_id, tags, $pg_future, Array[$pg_newest], $pg_version_tags from category where version=$pg_version);"; $sql.="insert into category_rule (select $pg_id, rule_id, tags, $pg_future from category_rule where version=$pg_version);"; $sql.="delete from category_current where category_id=$pg_id;"; $sql.="insert into category_current values ($pg_id, $pg_future, now());"; $sql.="commit;"; sql_query($sql, $db_central); return array("status"=>true, "version"=>$future); }
} $categories[$src[category]][]=$rule; } foreach($list_category as $cat_id=>$cat_data) { $rules=$categories[$cat_id]; $ret=""; $cat=new tags(); $f=popen("grep 'cat:$cat_id' $root_path/www/lang/en.js", "r"); $r=fgets($f); pclose($f); $cat->set("lang", "en"); if(preg_match("/lang_str\[\".*\"\]=\[ (\".*\", )?\"(.*)\" \];/", $r, $m)) { $cat->set("name", $m[2]); } else { $cat->set("name", $cat_id); } foreach(array("de", "it", "ja") as $lang) { $f=popen("grep 'cat:$cat_id' $root_path/www/lang/$lang.js", "r"); $r=fgets($f); pclose($f); if(preg_match("/lang_str\[\".*\"\]=\[ (\".*\", )?\"(.*)\" \];/", $r, $m)) { if($cat->get("name")!=$m[2]) $cat->set("name:$lang", $m[2]);
function save($param=array()) { global $current_user; global $db_central; $sql="begin;"; $version=uniqid(); $parent_version=$this->get_newest_version($db_central); $version_tags=new tags(); $version_tags->set("user", $current_user->username); $version_tags->set("date", Date("c")); $version_tags->set("msg", $param['msg']); $sql.="insert into category values ('{$this->id}', ".array_to_hstore($this->tags->data()).", '$version', Array['$parent_version'], ".array_to_hstore($version_tags->data()).");\n"; foreach($this->rules as $id=>$rule) { $sql.="insert into category_rule values ('{$this->id}', '{$rule->id}', ".array_to_hstore($rule->tags->data()).", '$version');\n"; } $sql.="update category_current set version='$version', now=now() where category_id='{$this->id}';\n"; $sql.="commit;\n"; sql_query($sql, $db_central); }