Example #1
0
 public function handler_admin($page)
 {
     if (!S::user()->hasRights(Group::from('qdj'), Rights::admin())) {
         return PL_FORBIDDEN;
     }
     $qdjs = QDJ::waiting();
     $qdjs->select(QDJSelect::all());
     $qdjs->order('date', false);
     $page->assign('qdjs', $qdjs);
     $page->addCssLink('qdj.css');
     $page->assign('title', "Planification des QDJ");
     $page->changeTpl('qdj/admin.tpl');
 }
Example #2
0
 public function vote($answer)
 {
     XDB::startTransaction();
     XDB::execute('INSERT INTO  qdj_votes
                           SET  qdj = {?}, uid = {?}, rank = 0, rule = "null"', $this->id(), S::user()->id());
     $vote = XDB::insertID();
     // Get the rank
     $rank = XDB::query('SELECT  COUNT(*)+1
                           FROM  qdj_votes
                          WHERE  qdj = {?} AND rank != 0', $this->id())->fetchOneCell();
     if ($rank == 1) {
         if ($this->writer === null) {
             $this->select(QDJSelect::all());
         }
         XDB::execute('INSERT INTO  qdj_votes
                               SET  qdj = {?}, uid = {?}, rank = 0, rule = 10', $this->id(), $this->writer->id());
     }
     $rule = null;
     switch ($rank) {
         case 1:
             $rule = '1';
             break;
         case 2:
             $rule = '2';
             break;
         case 3:
             $rule = '3';
             break;
         case 13:
             $rule = '4';
             break;
         case 42:
             $rule = '5';
             break;
         case 69:
             $rule = '6';
             break;
         case 314:
             $rule = '7';
             break;
         case substr(strrchr(IPAddress::get(), '.'), 1):
             $rule = '8';
             break;
         case date('d') + date('m'):
             $rule = '9';
             break;
     }
     XDB::execute('UPDATE qdj_votes
                      SET rank = {?}, rule = {?}
                    WHERE vote_id = {?}', $rank, $rule, $vote);
     XDB::commit();
     if ($answer == 1) {
         XDB::execute('UPDATE qdj SET count1 = count1+1 WHERE id={?}', $this->id());
     } else {
         XDB::execute('UPDATE qdj SET count2 = count2+1 WHERE id={?}', $this->id());
     }
 }