예제 #1
0
 /**
  *
  * @param
  * @return
  */
 function vote($formData)
 {
     if (empty($formData['poll_id']) || empty($formData['quest'])) {
         return 'Пожалуйста, будьте внимательны при участии в опросе. Необходимо указать как минимум 1 вариант ответа.';
     }
     $poll_id = $formData['poll_id'];
     $PollData = new Zx_Db_Table_PollData();
     $PollLog = new Zx_Db_Table_PollLog();
     #echo "DEBUG:<br><textarea rows=10 cols=100>" . print_r($formData, 1) . "</textarea><br>";
     foreach ($formData['quest'] as $data_id => $v) {
         // check poll data
         $select = $PollData->select()->where('poll_id = ?', $poll_id)->where('id = ?', $data_id);
         $row = $PollData->getRow($select);
         #echo "DEBUG:<br><textarea rows=10 cols=100>" . print_r($row, 1) . "</textarea><br>";die;
         // check poll spamming
         $ips = Zx_FrontEnd::getIP();
         $select = $PollLog->select()->where('poll_id = ?', $poll_id)->where('data_id = ?', $data_id)->where('ip = ?', new Zend_Db_Expr("INET_ATON('" . $ips['ip'] . "')"));
         #echo "DEBUG:<br><textarea rows=10 cols=100>" . $select . "</textarea><br>";die;
         $row = $PollLog->getRow($select);
         /* 			if ($row) {
         				return 'Данный IP-адрес (' . $ips['ip'] . ') уже использовался при участии в опросе.';# Использование 1 IP-адреса возможно в течении 1 суток.
         			}
         */
         // insert poll data
         $data = array('poll_id' => $poll_id, 'data_id' => $data_id, 'ip' => new Zend_Db_Expr("INET_ATON('" . $ips['ip'] . "')"));
         if (!empty($ips['ip2'])) {
             $data['ip2'] = ip2long($ips['ip']);
         }
         $res = $PollLog->insert($data);
         #echo "DEBUG:<br><textarea rows=10 cols=100>" . print_r($res, 1) . "</textarea><br>";
         // update poll data
         if ($res) {
             $data = array('votes' => new Zend_Db_Expr('votes+1'));
             $res = $PollData->update($data, 'poll_id = "' . $poll_id . '" AND id = "' . $data_id . '"');
             // update poll
             if ($res) {
                 $res = $this->update($data, 'id = ' . $poll_id);
             }
         }
     }
     return true;
 }
예제 #2
0
 function init()
 {
     $this->conf = Zend_Registry::get('conf');
     $this->initView();
     $this->viewScript = 'main.phtml';
     $this->view->host = Zx_FrontEnd::getHttpPrefix();
     // используется в хелперах меню
     $this->view->pathParts = Zx_FrontEnd::getPathParts($this->getRequest());
     //@TODO? use $this->p instead
     $this->view->divider = ' - ';
     // title / headers divider
     $this->view->content = '';
     //--> get parameters from request
     $this->id = $this->_getParam('id', null);
     if ($this->id) {
         $this->view->id = $this->id;
     }
     $this->view->topicId = $this->topicId = (int) $this->_getParam('topicId');
     $this->view->subtopicId = $this->subtopicId = (int) $this->_getParam('subtopicId');
     $sectionId = $this->getRequest()->getParam('sectionId');
     if ($sectionId) {
         Zend_Registry::set('sectionId', $sectionId);
         $this->view->sectionId = $this->sectionId = $sectionId;
     }
     $subsectionId = $this->getRequest()->getParam('subsectionId');
     if ($subsectionId) {
         Zend_Registry::set('subsectionId', $subsectionId);
         $this->subsectionId = $subsectionId;
     }
     $this->page = $this->_getParam('page', 1);
     Zend_Registry::set('page', $this->page);
     $this->view->p = $this->p = $this->getRequest()->getParams();
     /*
     [controller] => stores
     [action] => index
     [module] => default
     */
     $this->view->baseUrl = $this->getRequest()->getBaseUrl();
     $this->view->requestUri = $this->getRequest()->getRequestUri();
     #$this->view->refererUri = $this->getRequest()->getServer('HTTP_REFERER');#getHeader('REFERER')
     // base current controller URI
     $this->cURI = '/' . $this->p['controller'] . '/';
     // common models init
     if (empty($this->conf->app->FrontEnd)) {
         $this->fe = new Zx_FrontEnd();
     }
     $this->model('Articles', 'db');
     #$this->Articles = new Zx_Db_Table_Articles();
     $this->model('Content', 'db');
     #$this->Content = new Zx_Db_Table_Content();
     #$this->model('Feedback', 'db');#$this->Feedback = new Zx_Db_Table_Feedback();
     #$this->model('Topics', 'db');#$this->Topics = new Zx_Db_Table_Topics();
     $this->Topics = new Zx_Db_Table_TopicsTree();
     // since 5/21/2009
     // Создание экземпляров классов
     if (!empty($this->conf->libload)) {
         $a = $this->conf->libload->toArray();
         foreach ($a as $k => $v) {
             if ($v === true) {
                 $v = $k;
             }
             $this->{$k} = new $v();
         }
     }
     /*
     Array
     (
         [id] => women
         [module] => default
         [controller] => index
         [action] => index
     )
     */
     #echo "DEBUG:<br><textarea rows=10 cols=100>" . print_r($this->view->p, 1) . "</textarea><br>";die;
     //<--
     $this->initStrings();
     //TODO: move to projects?
     if (is_object($this->conf->auth) && empty($this->conf->auth->strict)) {
         $this->initAuth($this->conf->auth);
     }
     // todo!
     $this->_flashMessenger = $this->_helper->getHelper('FlashMessenger');
     $this->view->messages = $this->_flashMessenger->getMessages();
     #d($this->view->messages);
 }