Exemplo n.º 1
0
 /**
  * Set Views (pH Views) Statistics with a verification session to avoid duplication in the number of page views.
  *
  * @static
  * @param integer $iId
  * @param string $sTable
  * @return void
  */
 public static function setView($iId, $sTable)
 {
     $oSession = new \PH7\Framework\Session\Session();
     $sSessionName = 'pHV' . $iId . $sTable;
     if (!$oSession->exists($sSessionName)) {
         Mvc\Model\Statistic::setView($iId, $sTable);
         $oSession->set($sSessionName, 1);
     }
     unset($oSession);
 }
Exemplo n.º 2
0
 public static function display()
 {
     if (isset($_POST['submit_update_ads'])) {
         if (\PFBC\Form::isValid($_POST['submit_update_ads'])) {
             new UpdateAdsFormProcess();
         }
         Framework\Url\HeaderUrl::redirect();
     }
     $oPage = new Page();
     $oAdsModel = new AdsCoreModel();
     $sTable = AdsCore::getTable();
     $sCSRFToken = (new Framework\Security\CSRF\Token())->generate('ads');
     $oPage->getTotalPages($oAdsModel->total($sTable), 10);
     $oAds = $oAdsModel->get(null, $oPage->getFirstItem(), $oPage->getNbItemsByPage(), $sTable);
     unset($oPage, $oAdsModel);
     $oSysVar = new SysVar();
     foreach ($oAds as $oRow) {
         $oForm = new \PFBC\Form('form_update_ads', 500);
         $oForm->configure(array('action' => ''));
         $oForm->addElement(new \PFBC\Element\Hidden('submit_update_ads', 'form_update_ads'));
         $oForm->addElement(new \PFBC\Element\Token('update_ads'));
         // Begin ads div tags
         $oForm->addElement(new \PFBC\Element\HTMLExternal('<div id="ad_' . $oRow->adsId . '">'));
         $oForm->addElement(new \PFBC\Element\Hidden('id_ads', $oRow->adsId));
         $oForm->addElement(new \PFBC\Element\Textbox(t('Title:'), 'title', array('value' => $oRow->name, 'required' => 1, 'validation' => new \PFBC\Validation\Str(2, 40))));
         $oForm->addElement(new \PFBC\Element\HTMLExternal('<p>' . t('Preview Ads:') . '</p>'));
         $oForm->addElement(new \PFBC\Element\HTMLExternal('<div class="border">' . $oSysVar->parse($oRow->code) . '</div>'));
         // ID textarea form was generated with "mt_rand" because it is faster than "uniqid"
         // See also this discussion we asked: http://stackoverflow.com/questions/9152600/uniqid-versus-mt-rand-php-function
         $oForm->addElement(new \PFBC\Element\Textarea(t('Advertisement:'), 'code', array('id' => mt_rand(), 'value' => $oSysVar->parse($oRow->code), 'required' => 1)));
         // mt_rand() function for generate an ID different if it causes problems in the display.
         $oForm->addElement(new \PFBC\Element\Button(t('Update'), 'submit', array('id' => mt_rand())));
         $oForm->addElement(new \PFBC\Element\HTMLExternal(t('Views: %0%', Framework\Mvc\Model\Statistic::getView($oRow->adsId, $sTable)) . ' | <a class="medium_button" href="javascript:void(0)" onclick="ads(\'delete\',' . $oRow->adsId . ',\'' . $sCSRFToken . '\')">' . t('Delete') . '</a> | '));
         if ($oRow->active == 1) {
             $oForm->addElement(new \PFBC\Element\HTMLExternal('<a class="medium_button" href="javascript:void(0)" onclick="ads(\'deactivate\',' . $oRow->adsId . ',\'' . $sCSRFToken . '\')">' . t('Deactivate') . '</a>'));
         } else {
             $oForm->addElement(new \PFBC\Element\HTMLExternal('<a class="medium_button" href="javascript:void(0)" onclick="ads(\'activate\',' . $oRow->adsId . ',\'' . $sCSRFToken . '\')">' . t('Activate') . '</a>'));
         }
         // End ads div tags
         $oForm->addElement(new \PFBC\Element\HTMLExternal('</div>'));
         $oForm->render();
     }
 }