* changed the iframe to object as the former is deprecated in xhtml 1.0
[vsc.git] / adm / _pages / index / code.php
blobb440afe092eeb675cc411abde181aace24b3753d
1 <?php
2 class index extends tsAdminPage {
3 private $menu;
5 public function __construct(){
6 parent::__construct();
8 // $this->user = new tsUsers();
10 $o = new tdoOptions($this->db);
11 $o->option_name = 'title';
12 $o->findFirst();
14 $this->mnuBuild ();
16 $this->varArray['menu'] = $this->menu;
17 $this->varArray['tit'] = $o->option_value;
18 $this->varArray['title'] = ' ['.$this->user->name.' @ '.$this->varArray['tit'].']';
20 $action = tsPage::getRequest('do');
22 // avoid making useless queries if $action = edit || delete
23 if (empty($action)) {
24 $action = null;
25 } elseif (!in_array($action, get_class_methods($this))) {
26 $action = 'menu'.ucfirst($action);
29 if (!empty ($action)) {
30 $this->$action();
33 if (empty($this->varArray['mainFile'])) {
34 $pt = new tdoPosts($this->db);
35 $pt->post_active = "Y";
37 $pt->addOrder($pt->post_id, false);
39 $ps = $pt->getArray();
41 foreach ($ps as $post){
42 $post['eaction'] = tsPage::setRequest(get_class($this), array('do' => 'post', 'i' => $post['post_id']));
43 $post['daction'] = tsPage::setRequest(get_class($this), array('do' => 'delete', 'i' => $post['post_id']));
45 $post['post_title'] = stripslashes(strip_tags($post['post_title']));
46 $post['post_body'] = stripslashes(strip_tags($post['post_body']));
47 $posts[] = $post;
50 if (empty($posts)) {
51 $posts[0]['post_title'] = '&laquo; empty &raquo;';
52 $posts[0]['post_body'] = 'There are no posts currently';
53 $posts[0]['eaction'] = tsPage::setRequest(get_class($this), 'do=post');
56 $this->varArray['posts'] = $posts;
57 $this->varArray['mainFile'] = dirname(__FILE__).'/pages/allposts.tpl';
61 private function mnuBuild () {
62 $menuKeys = get_class_methods (get_class());
63 $notGood = get_class_methods (get_parent_class());
65 $menuKeys = array_diff ($menuKeys, $notGood);
67 foreach ($menuKeys as $key) {
68 if (stristr ($key, 'menu')){
69 $key = strtolower (preg_replace('/menu/','', $key));
70 $this->menu[$key] = tsPage::setRequest (get_class($this), array('do' => $key));
75 public function up () {
76 // level up - not used
77 //tsPage::redirect(str_replace('&amp;','&',tsPage::setRequest('../')));
80 public function menuAdd(){
81 $this->post();
84 public function delete () {
85 $id = tsPage::getRequest('i');
87 $post = new tdoPosts($this->db);
88 // $post->post_id = $id;
90 $post->post_active = "N";
92 $post->update($id);
94 tsPage::redirect(str_replace('&amp;', '&',tsPage::setRequest(get_class($this))));
97 public function edit () {
98 $postId = tsPage::getRequest('i');
100 $post = new tdoPosts ($this->db);
101 $cp = new tdoCategoriesPosts ($this->db);
103 if (!empty($postId)) {
104 $post->post_id = $postId;
105 $post->buildObj ();
108 $title = tsPage::getRequest('t');
109 $post->clean ($title, false);
110 $post->post_title = $title; // post title
112 $body = tsPage::getRequest('x');
113 $post->clean ($body);
114 $post->post_body = $body; // post body
116 $modTime = tsPage::getRequest('d');
117 var_dump($modTime); die;
119 if (!empty($modTime)) {
120 $post->post_time = date("Y-m-d G:i:s");
123 $post->post_author = $this->user->name;
125 $post->post_private = (tsPage::getRequest('p') ? 'Y' : 'N');
127 // getting the category id based on name
128 $incCat = tsPage::getRequest ('c');
130 if (!empty($body) && !empty($title)) {
131 $id = $post->replace ($postId);
134 if (!is_array($incCat))
135 $incCat[] = $incCat;
137 if (!empty ($id)) {
138 $cp->addWhere ($cp->post_id, '=', $id);
139 $cp->delete ();
141 foreach ($incCat as $catId) {
142 $cp->category_id = $catId;
143 $cp->post_id = $id;
145 $cp->insert ();
149 tsPage::redirect(str_replace('&amp;','&',tsPage::setRequest(get_class($this), array('do'=> 'post', 'i' => (int)$id))));
152 public function post () {
153 $postId = tsPage::getRequest('i');
154 // $this->initiateDisplay();
156 $this->varArray['action'] = tsPage::setRequest (get_class($this), 'do=edit');
157 $this->varArray['mainFile'] = dirname (__FILE__).'/pages/edit.tpl';
159 $c = new tdoCategories ($this->db);
160 $cat = $c->getArray ();
162 $p = new tdoPosts($this->db);
163 if (!empty($postId)) {
164 $p->post_id = $postId;
165 $posts = $p->getArray (1);
167 // TODO: stripslashes is mandatory - also I should use htmlentities if outputting application/xhtml+xml
168 $posts[0]['post_title'] = htmlentities (stripslashes ($posts[0]['post_title']), ENT_QUOTES, 'UTF-8');
169 $posts[0]['post_body'] = htmlentities (stripslashes ($posts[0]['post_body']), ENT_QUOTES, 'UTF-8');
171 // $posts[0]['post_flags'] = ($posts[0]['post_flags'] & P_PRIVATE);
172 $this->varArray['post'] = $posts[0];
174 $cp = new tdoCategoriesPosts ($this->db);
175 $cp->post_id = $postId;
176 $refs = $cp->getArray ();
178 foreach ($refs as $ref) {
179 $tref[] = $ref['category_id'];
182 foreach ($cat as $key => $catData) {
183 if (is_array ($tref) && in_array ($catData['category_id'], $tref)) {
184 $catData['category_active'] = true;
185 $cat[$key] = $catData;
190 $this->varArray['categories'] = $cat;
191 $this->varArray['now'] = date('Y-m-d G:i:s');
192 $this->varArray['upload_url'] = tsPage::setRequest ('upload', array('i' => $postId));
195 public function catedit () {
196 // $c = new tdoCategories ($this->db);
198 // $v = tsPage::getRequest('v');
199 // $i = tsPage::getRequest('i');
201 // $c->category_name = $v ;
203 // $c->update ($i);
205 // tsPage::redirect(str_replace('&amp;','&',tsPage::setRequest(get_class($this))));
208 public function optedit () {
209 $o = new tdoOptions($this->db);
211 $v = tsPage::getRequest('v');
212 $i = tsPage::getRequest('i');
213 $o->option_value = $v ;
215 $o->update ($i);
217 tsPage::redirect(str_replace('&amp;','&',tsPage::setRequest (get_class($this))));
220 public function menuOpt () {
221 $o = new tdoOptions($this->db);
222 $o->option_modif = 'Y';
223 $os = $o->getArray();
225 foreach ($os as $opt){
226 $opt['action'] = tsPage::setRequest(get_class($this), array('do'=>'optedit', 'id' => $opt['option_id']));
227 $options[] = $opt;
229 // var_dump($options);
230 $this->varArray['options'] = $options;
231 $this->varArray['mainFile'] = dirname(__FILE__).'/pages/options.tpl';
232 //tsPage::redirect(str_replace('&amp;','&',tsPage::setRequest(get_class($this), 'do=opt')));
235 public function menuLogout () {
236 tsPage::redirect(str_replace('&amp;','&',tsPage::setRequest('login', 'do=logout')));
239 public function menuMain () {
240 tsPage::redirect(str_replace('&amp;','&',tsPage::setRequest(get_class($this))));
243 public function menuCategories () {
244 // tsPage::redirect(str_replace('&amp;','&',tsPage::setRequest(get_class($this))));
245 $c = new tdoCategories($this->db);
247 $c->category_active = 'Y';
248 $cs = $c->getArray();
249 // var_dump($cs);
250 foreach ($cs as $cat){
251 $cat['action'] = tsPage::setRequest(get_class($this), array('do'=>'catedit', 'id' => $opt['category_id']));
252 $categories[] = $cat;
256 $this->varArray['categories'] = $categories;
257 $this->varArray['mainFile'] = dirname(__FILE__).'/pages/categories.tpl';