* dumb commit
[vsc.git] / adm / _pages / index / code.php
blob1375ce33a22767332d4b64ecf2d12deed7698d4f
1 <?php
2 class index extends tsAdminPage {
3 private $menu;
5 public function __construct(){
6 parent::__construct();
8 $o = new tdoOptions($this->db);
9 $o->option_name = 'title';
10 $o->findFirst();
12 $this->mnuBuild ();
14 $this->varArray['menu'] = $this->menu;
15 $this->varArray['tit'] = $o->option_value;
16 $this->varArray['title'] = ' ['.$this->user->user_name.' @ '.$this->varArray['tit'].']';
18 $action = tsPage::getRequest('do');
20 // avoid making useless queries if $action = edit || delete
21 if (empty($action)) {
22 $action = null;
23 } elseif (!in_array($action, get_class_methods ($this))) {
24 $action = 'menu'.ucfirst($action);
27 if (!empty ($action) && in_array($action, get_class_methods ($this))) {
28 $this->$action();
31 if (empty($this->varArray['mainFile'])) {
32 $pt = new tdoPosts($this->db);
33 $pt->post_active = "Y";
35 $pt->addOrder($pt->post_id, false);
37 $ps = $pt->getArray();
39 foreach ($ps as $post){
40 $post['eaction'] = tsPage::setRequest(get_class($this), array('do' => 'post', 'i' => $post['post_id']));
41 $post['daction'] = tsPage::setRequest(get_class($this), array('do' => 'delete', 'i' => $post['post_id']));
43 $post['post_title'] = stripslashes(strip_tags($post['post_title']));
44 $post['post_body'] = stripslashes(strip_tags($post['post_body']));
45 $posts[] = $post;
48 if (empty($posts)) {
49 $posts[0]['post_title'] = '&laquo; empty &raquo;';
50 $posts[0]['post_body'] = 'There are no posts currently';
51 $posts[0]['eaction'] = tsPage::setRequest(get_class($this), 'do=post');
54 $this->varArray['posts'] = $posts;
55 $this->varArray['mainFile'] = dirname(__FILE__).'/pages/allposts.tpl';
59 private function mnuBuild () {
60 $menuKeys = get_class_methods (get_class());
61 $notGood = get_class_methods (get_parent_class());
63 $menuKeys = array_diff ($menuKeys, $notGood);
65 foreach ($menuKeys as $key) {
66 if (stristr ($key, 'menu')){
67 $key = strtolower (preg_replace('/menu/','', $key));
68 $this->menu[$key] = tsPage::setRequest (get_class($this), array('do' => $key));
73 public function menuAdd(){
74 $this->post();
77 public function delete () {
78 $id = tsPage::getRequest('i');
80 $post = new tdoPosts($this->db);
81 // $post->post_id = $id;
83 $post->post_active = "N";
85 $post->update($id);
87 tsPage::redirect( tsPage::setRequest(get_class($this)) );
90 public function edit () {
91 $postId = tsPage::getRequest('i');
93 $post = new tdoPosts ($this->db);
94 $cp = new tdoCategoriesPosts ($this->db);
96 if (!empty ($postId)) {
97 $post->post_id = $postId;
98 $post->buildObj ();
101 $title = tsPage::getRequest('t');
102 $post->clean ($title, false);
103 $post->post_title = $title; // post title
105 $body = tsPage::getRequest('x');
106 // this is just for fun, so I can display these values in the posts,
107 // but not have them converted at edit time
108 $body = str_replace (array('$TIME$', '$QUERIES$', '$MEMUSED$'),
109 array('%TIME%','%QUERIES%', '%MEMUSED%'), $body);
112 $post->clean ($body);
113 $post->post_body = $body; // post body
116 $modTime = tsPage::getRequest('d');
118 if (!empty($modTime)) {
119 $post->post_time = date("Y-m-d G:i:s");
122 $post->post_author = $this->user->uid;
124 $post->post_private = (tsPage::getRequest('p') ? 'Y' : 'N');
126 // getting the category id based on name
127 $incCat = tsPage::getRequest ('c');
129 if (!empty($body) && !empty($title)) {
130 $id = $post->replace ($postId);
133 if (!is_array($incCat))
134 $incCat[] = $incCat;
136 if (!empty ($id)) {
137 $cp->addWhere ($cp->post_id, '=', $id);
138 $cp->delete ();
140 foreach ($incCat as $catId) {
141 $cp->category_id = $catId;
142 $cp->post_id = $id;
144 $cp->insert ();
148 tsPage::redirect( tsPage::setRequest(get_class($this), array('do'=> 'post', 'i' => (int)$id)) );
151 public function post () {
152 $postId = tsPage::getRequest('i');
153 // $this->initiateDisplay();
155 $this->varArray['action'] = tsPage::setRequest (get_class($this), 'do=edit');
156 $this->varArray['mainFile'] = dirname (__FILE__).'/pages/edit.tpl';
158 $c = new tdoCategories ($this->db);
159 $c->category_active = 'Y';
161 $cat = $c->getArray ();
163 $p = new tdoPosts($this->db);
164 if (!empty($postId)) {
165 $p->post_id = $postId;
166 $posts = $p->getArray (1);
168 // TODO: stripslashes is mandatory - also I should use htmlentities if outputting application/xhtml+xml
169 $posts[0]['post_title'] = htmlentities (stripslashes ($posts[0]['post_title']), ENT_QUOTES, 'UTF-8');
170 $posts[0]['post_body'] = htmlentities (stripslashes ($posts[0]['post_body']), ENT_QUOTES, 'UTF-8');
172 // this is just for fun, so I can display these values in the posts, but not have them converted at edit time
173 $posts[0]['post_body'] = str_replace(array('%TIME%','%QUERIES%', '%MEMUSED%'), array('$TIME$', '$QUERIES$', '$MEMUSED$'), $posts[0]['post_body']);
175 $this->varArray['post'] = $posts[0];
177 $cp = new tdoCategoriesPosts ($this->db);
178 $cp->post_id = $postId;
180 $refs = $cp->getArray ();
182 foreach ($refs as $ref) {
183 $tref[] = $ref['category_id'];
186 foreach ($cat as $key => $catData) {
187 if (is_array ($tref) && in_array ($catData['category_id'], $tref)) {
188 $catData['category_set'] = true;
189 $cat[$key] = $catData;
194 if (!empty($postId ))
195 $this->varArray['this_post'] = '#p'.$postId ;
197 $this->varArray['categories'] = $cat;
198 $this->varArray['now'] = date('Y-m-d G:i:s');
199 $this->varArray['upload_url'] = tsPage::setRequest ('upload', array('i' => $postId));
202 public function catedit () {
203 $c = new tdoCategories ($this->db);
205 // id
206 $i = tsPage::getRequest('i');
207 // delete
208 if (tsPage::getRequest('delete') == 'yes'){
209 $c->category_active = 'N';
212 // name
213 $n = tsPage::getRequest('n');
214 // description
215 $d = tsPage::getRequest('d');
216 // private
217 $p = tsPage::getRequest('p');
219 $c->category_name = $n;
220 $c->category_description = $d;
221 $c->category_private = $p;
223 $c->replace ($i);
225 tsPage::redirect ( tsPage::setRequest(get_class($this), array('do' => 'categories')));
228 public function menuCategories () {
229 // tsPage::redirect( tsPage::setRequest(get_class($this)) );
230 $c = new tdoCategories($this->db);
232 $c->category_active = 'Y';
233 $cs = $c->getArray();
235 $this->varArray['categories'] = $cs;
236 $this->varArray['action'] = tsPage::setRequest(get_class($this), array('do'=>'catedit'));
237 $this->varArray['mainFile'] = dirname(__FILE__) . '/pages/categories.tpl';
241 public function optedit () {
242 $o = new tdoOptions($this->db);
243 // id
244 $i = tsPage::getRequest('i');
246 // delete
247 if (tsPage::getRequest('delete') == 'yes'){
248 $rows = $o->delete ($i);
249 } else {
250 // value
251 $v = tsPage::getRequest ('v');
252 $a = tsPage::getRequest ('a') == 'Y' ? 'Y' : 'N';
253 $n = tsPage::getRequest ('n');
255 if (!empty($n)) {
256 $o->option_name = $n;
259 $o->option_value = $v;
260 $o->option_modif = $a;
262 $o->replace ($i);
264 tsPage::redirect( tsPage::setRequest (get_class($this), 'do=options' ));
267 public function menuOptions () {
268 $o = new tdoOptions($this->db);
269 $os = $o->getArray();
271 $this->varArray['options'] = $os;
272 $this->varArray['action'] = tsPage::setRequest(get_class($this), array('do'=>'optedit'));
273 $this->varArray['mainFile'] = dirname(__FILE__).'/pages/options.tpl';
276 public function menuMain () {
277 tsPage::redirect( tsPage::setRequest(get_class($this) ));
280 public function menuLogout () {
281 tsPage::redirect( tsPage::setRequest('login', 'do=logout') );