Exemplo n.º 1
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $this->frm->cleanupFields();
         // validate fields
         $this->frm->getField('title')->isFilled(BL::err('QuestionIsRequired'));
         $this->frm->getField('answer')->isFilled(BL::err('AnswerIsRequired'));
         $this->frm->getField('category_id')->isFilled(BL::err('CategoryIsRequired'));
         $this->meta->validate();
         if ($this->frm->isCorrect()) {
             // build item
             $item['meta_id'] = $this->meta->save();
             $item['category_id'] = $this->frm->getField('category_id')->getValue();
             $item['user_id'] = BackendAuthentication::getUser()->getUserId();
             $item['language'] = BL::getWorkingLanguage();
             $item['question'] = $this->frm->getField('title')->getValue();
             $item['answer'] = $this->frm->getField('answer')->getValue(true);
             $item['created_on'] = BackendModel::getUTCDate();
             $item['hidden'] = $this->frm->getField('hidden')->getValue();
             $item['sequence'] = BackendFaqModel::getMaximumSequence($this->frm->getField('category_id')->getValue()) + 1;
             // save the data
             $item['id'] = BackendFaqModel::insert($item);
             BackendTagsModel::saveTags($item['id'], $this->frm->getField('tags')->getValue(), $this->URL->getModule());
             BackendModel::triggerEvent($this->getModule(), 'after_add', array('item' => $item));
             // add search index
             BackendSearchModel::saveIndex('faq', $item['id'], array('title' => $item['question'], 'text' => $item['answer']));
             $this->redirect(BackendModel::createURLForAction('index') . '&report=added&var=' . urlencode($item['question']) . '&highlight=row-' . $item['id']);
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Loads the datagrid with the groups
  *
  * @return	void
  */
 private function loadDataGrid()
 {
     // create datagrid
     $this->dataGrid = new BackendDataGridDB(BackendMailmotorModel::QRY_DATAGRID_BROWSE_GROUPS);
     $this->dataGrid->setColumnsHidden(array('language', 'is_default'));
     // sorting columns
     $this->dataGrid->setSortingColumns(array('name', 'created_on'), 'created_on');
     $this->dataGrid->setSortParameter('desc');
     // set colum URLs
     $this->dataGrid->setColumnURL('name', BackendModel::createURLForAction('addresses') . '&group_id=[id]');
     // set the datagrid ID so we don't run into trouble with multiple datagrids that use mass actions
     $this->dataGrid->setAttributes(array('id' => 'dgGroups'));
     // add the multicheckbox column
     $this->dataGrid->setMassActionCheckboxes('checkbox', '[id]', BackendMailmotorModel::getDefaultGroupIds());
     $this->dataGrid->setColumnsSequence('checkbox', 'name', 'created_on', 'language');
     // add mass action dropdown
     $ddmMassAction = new SpoonFormDropdown('action', array('delete' => BL::lbl('Delete')), 'delete');
     $this->dataGrid->setMassAction($ddmMassAction);
     // set column functions
     $this->dataGrid->setColumnFunction(array('BackendDataGridFunctions', 'getTimeAgo'), array('[created_on]'), 'created_on', true);
     // add delete column
     $this->dataGrid->addColumnAction('custom_fields', null, BL::lbl('CustomFields'), BackendModel::createURLForAction('custom_fields') . '&group_id=[id]', BL::lbl('CustomFields'), array('class' => 'button icon iconEdit linkButton'));
     $this->dataGrid->addColumnAction('export', null, BL::lbl('Export'), BackendModel::createURLForAction('export_addresses') . '&id=[id]', BL::lbl('Export'), array('class' => 'button icon iconExport linkButton'));
     $this->dataGrid->addColumn('edit', null, BL::lbl('Edit'), BackendModel::createURLForAction('edit_group') . '&id=[id]', BL::lbl('Edit'));
     // add styles
     $this->dataGrid->setColumnAttributes('name', array('class' => 'title'));
     // set paging limit
     $this->dataGrid->setPagingLimit(self::PAGING_LIMIT);
 }
Exemplo n.º 3
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         // cleanup the submitted fields, ignore fields that were added by hackers
         $this->frm->cleanupFields();
         // validate fields
         $this->frm->getField('author')->isFilled(BL::err('AuthorIsRequired'));
         $this->frm->getField('email')->isEmail(BL::err('EmailIsInvalid'));
         $this->frm->getField('text')->isFilled(BL::err('FieldIsRequired'));
         if ($this->frm->getField('website')->isFilled()) {
             $this->frm->getField('website')->isURL(BL::err('InvalidURL'));
         }
         // no errors?
         if ($this->frm->isCorrect()) {
             // build item
             $item['id'] = $this->id;
             $item['status'] = $this->record['status'];
             $item['author'] = $this->frm->getField('author')->getValue();
             $item['email'] = $this->frm->getField('email')->getValue();
             $item['website'] = $this->frm->getField('website')->isFilled() ? $this->frm->getField('website')->getValue() : null;
             $item['text'] = $this->frm->getField('text')->getValue();
             // insert the item
             BackendBlogModel::updateComment($item);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_edit_comment', array('item' => $item));
             // everything is saved, so redirect to the overview
             $this->redirect(BackendModel::createURLForAction('comments') . '&report=edited-comment&id=' . $item['id'] . '&highlight=row-' . $item['id'] . '#tab' . SpoonFilter::toCamelCase($item['status']));
         }
     }
 }
Exemplo n.º 4
0
 /**
  * Validate the form
  *
  * @return	void
  */
 private function validateForm()
 {
     // is the form submitted?
     if ($this->frm->isSubmitted()) {
         // set callback for generating an unique URL
         $this->meta->setURLCallback('BackendBlogModel', 'getURLForCategory');
         // cleanup the submitted fields, ignore fields that were added by hackers
         $this->frm->cleanupFields();
         // validate fields
         $this->frm->getField('title')->isFilled(BL::err('TitleIsRequired'));
         // validate meta
         $this->meta->validate();
         // no errors?
         if ($this->frm->isCorrect()) {
             // build item
             $item['title'] = $this->frm->getField('title')->getValue();
             $item['language'] = BL::getWorkingLanguage();
             $item['meta_id'] = $this->meta->save();
             // insert the item
             $item['id'] = BackendBlogModel::insertCategory($item);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_add_category', array('item' => $item));
             // everything is saved, so redirect to the overview
             $this->redirect(BackendModel::createURLForAction('categories') . '&report=added-category&var=' . urlencode($item['title']) . '&highlight=row-' . $item['id']);
         }
     }
 }
Exemplo n.º 5
0
 /**
  * Execute the action
  *
  * @return	void
  */
 public function execute()
 {
     // get parameters
     $this->id = $this->getParameter('id', 'int');
     // does the item exist
     if ($this->id !== null && BackendPagesModel::existsTemplate($this->id)) {
         // call parent, this will probably add some general CSS/JS or other required files
         parent::execute();
         // init var
         $success = false;
         // get template (we need the title)
         $item = BackendPagesModel::getTemplate($this->id);
         // valid template?
         if (!empty($item)) {
             // delete the page
             $success = BackendPagesModel::deleteTemplate($this->id);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_delete_template', array('id' => $this->id));
             // build cache
             BackendPagesModel::buildCache(BL::getWorkingLanguage());
         }
         // page is deleted, so redirect to the overview
         if ($success) {
             $this->redirect(BackendModel::createURLForAction('templates') . '&theme=' . $item['theme'] . '&report=deleted-template&var=' . urlencode($item['label']));
         } else {
             $this->redirect(BackendModel::createURLForAction('templates') . '&error=non-existing');
         }
     } else {
         $this->redirect(BackendModel::createURLForAction('templates') . '&error=non-existing');
     }
 }
Exemplo n.º 6
0
 /**
  * Parse the correct messages into the template
  */
 protected function parse()
 {
     parent::parse();
     // grab the error-type from the parameters
     $errorType = $this->getParameter('type');
     // set correct headers
     switch ($errorType) {
         case 'module-not-allowed':
         case 'action-not-allowed':
             SpoonHTTP::setHeadersByCode(403);
             break;
         case 'not-found':
             SpoonHTTP::setHeadersByCode(404);
             break;
     }
     // querystring provided?
     if ($this->getParameter('querystring') !== null) {
         // split into file and parameters
         $chunks = explode('?', $this->getParameter('querystring'));
         // get extension
         $extension = SpoonFile::getExtension($chunks[0]);
         // if the file has an extension it is a non-existing-file
         if ($extension != '' && $extension != $chunks[0]) {
             // set correct headers
             SpoonHTTP::setHeadersByCode(404);
             // give a nice error, so we can detect which file is missing
             echo 'Requested file (' . htmlspecialchars($this->getParameter('querystring')) . ') not found.';
             // stop script execution
             exit;
         }
     }
     // assign the correct message into the template
     $this->tpl->assign('message', BL::err(SpoonFilter::toCamelCase(htmlspecialchars($errorType), '-')));
 }
Exemplo n.º 7
0
 /**
  * Validate the form.
  */
 private function validateForm()
 {
     // is the form submitted?
     if ($this->frm->isSubmitted()) {
         // cleanup the submitted fields, ignore fields that were added by hackers
         $this->frm->cleanupFields();
         // get field
         $txtName = $this->frm->getField('name');
         // name filled in?
         if ($txtName->isFilled(BL::getError('NameIsRequired'))) {
             // name exists?
             if (BackendProfilesModel::existsGroupName($txtName->getValue())) {
                 // set error
                 $txtName->addError(BL::getError('GroupNameExists'));
             }
         }
         // no errors?
         if ($this->frm->isCorrect()) {
             // build item
             $values['name'] = $txtName->getValue();
             // insert values
             $id = BackendProfilesModel::insertGroup($values);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_add_group', array('item' => $values));
             // everything is saved, so redirect to the overview
             $this->redirect(BackendModel::createURLForAction('groups') . '&report=group-added&var=' . urlencode($values['name']) . '&highlight=row-' . $id);
         }
     }
 }
Exemplo n.º 8
0
 /**
  * Execute the action
  */
 public function execute()
 {
     parent::execute();
     // get parameters
     $mailingId = SpoonFilter::getPostValue('mailing_id', null, '', 'int');
     $sendOnDate = SpoonFilter::getPostValue('send_on_date', null, BackendModel::getUTCDate('d/m/Y'));
     $sendOnTime = SpoonFilter::getPostValue('send_on_time', null, BackendModel::getUTCDate('H:i'));
     $messageDate = $sendOnDate;
     // validate mailing ID
     if ($mailingId == '') {
         $this->output(self::BAD_REQUEST, null, 'Provide a valid mailing ID');
     }
     if ($sendOnDate == '' || $sendOnTime == '') {
         $this->output(self::BAD_REQUEST, null, 'Provide a valid send date date provided');
     }
     // record is empty
     if (!BackendMailmotorModel::existsMailing($mailingId)) {
         $this->output(self::BAD_REQUEST, null, BL::err('MailingDoesNotExist', 'mailmotor'));
     }
     // reverse the date and make it a proper
     $explodedDate = explode('/', $sendOnDate);
     $sendOnDate = $explodedDate[2] . '-' . $explodedDate[1] . '-' . $explodedDate[0];
     // calc full send timestamp
     $sendTimestamp = strtotime($sendOnDate . ' ' . $sendOnTime);
     // build data
     $item['id'] = $mailingId;
     $item['send_on'] = BackendModel::getUTCDate('Y-m-d H:i:s', $sendTimestamp);
     $item['edited_on'] = BackendModel::getUTCDate('Y-m-d H:i:s');
     // update mailing
     BackendMailmotorModel::updateMailing($item);
     // trigger event
     BackendModel::triggerEvent($this->getModule(), 'after_edit_mailing_step4', array('item' => $item));
     // output
     $this->output(self::OK, array('mailing_id' => $mailingId, 'timestamp' => $sendTimestamp), sprintf(BL::msg('SendOn', $this->getModule()), $messageDate, $sendOnTime));
 }
Exemplo n.º 9
0
 /**
  * Execute the action
  *
  * @return	void
  */
 public function execute()
 {
     // call parent, this will probably add some general CSS/JS or other required files
     parent::execute();
     // get parameters
     $id = SpoonFilter::getPostValue('id', null, '', 'int');
     $name = trim(SpoonFilter::getPostValue('value', null, '', 'string'));
     // validate
     if ($name == '') {
         $this->output(self::BAD_REQUEST, null, 'no name provided');
     }
     // get existing id
     $existingId = BackendMailmotorModel::getCampaignId($name);
     // existing campaign
     if ($existingId !== 0 && $id !== $existingId) {
         $this->output(self::ERROR, array('id' => $existingId, 'error' => true), BL::err('CampaignExists', $this->getModule()));
     }
     // build array
     $item = array();
     $item['id'] = $id;
     $item['name'] = $name;
     $item['created_on'] = BackendModel::getUTCDate('Y-m-d H:i:s');
     // get page
     $rows = BackendMailmotorModel::updateCampaign($item);
     // trigger event
     BackendModel::triggerEvent($this->getModule(), 'edited_campaign', array('item' => $item));
     // output
     if ($rows !== 0) {
         $this->output(self::OK, array('id' => $id), BL::msg('CampaignEdited', $this->getModule()));
     } else {
         $this->output(self::ERROR, null, BL::err('CampaignNotEdited', $this->getModule()));
     }
 }
Exemplo n.º 10
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $this->frm->cleanupFields();
         // validate fields
         $this->frm->getField('title')->isFilled(BL::err('TitleIsRequired'));
         if ($this->frm->isCorrect()) {
             // build item
             $item['id'] = BackendContentBlocksModel::getMaximumId() + 1;
             $item['user_id'] = BackendAuthentication::getUser()->getUserId();
             $item['template'] = count($this->templates) > 1 ? $this->frm->getField('template')->getValue() : $this->templates[0];
             $item['language'] = BL::getWorkingLanguage();
             $item['title'] = $this->frm->getField('title')->getValue();
             $item['text'] = $this->frm->getField('text')->getValue();
             $item['hidden'] = $this->frm->getField('hidden')->getValue() ? 'N' : 'Y';
             $item['status'] = 'active';
             $item['created_on'] = BackendModel::getUTCDate();
             $item['edited_on'] = BackendModel::getUTCDate();
             // insert the item
             $item['revision_id'] = BackendContentBlocksModel::insert($item);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_add', array('item' => $item));
             // everything is saved, so redirect to the overview
             $this->redirect(BackendModel::createURLForAction('index') . '&report=added&var=' . urlencode($item['title']) . '&highlight=row-' . $item['id']);
         }
     }
 }
Exemplo n.º 11
0
 /**
  * Load the datagrids
  *
  * @return	void
  */
 private function loadDataGrids()
 {
     // load all categories
     $categories = BackendFaqModel::getCategories();
     // run over categories and create datagrid for each one
     foreach ($categories as $category) {
         // create datagrid
         $dataGrid = new BackendDataGridDB(BackendFaqModel::QRY_DATAGRID_BROWSE, array(BL::getWorkingLanguage(), $category['id']));
         // set attributes
         $dataGrid->setAttributes(array('class' => 'dataGrid sequenceByDragAndDrop'));
         // disable paging
         $dataGrid->setPaging(false);
         // set colum URLs
         $dataGrid->setColumnURL('question', BackendModel::createURLForAction('edit') . '&id=[id]');
         // set colums hidden
         $dataGrid->setColumnsHidden(array('category_id', 'sequence'));
         // add edit column
         $dataGrid->addColumn('edit', null, BL::lbl('Edit'), BackendModel::createURLForAction('edit') . '&id=[id]', BL::lbl('Edit'));
         // add a column for the handle, so users have something to hold while draging
         $dataGrid->addColumn('dragAndDropHandle', null, '<span>' . BL::lbl('Move') . '</span>');
         // make sure the column with the handler is the first one
         $dataGrid->setColumnsSequence('dragAndDropHandle');
         // add a class on the handler column, so JS knows this is just a handler
         $dataGrid->setColumnAttributes('dragAndDropHandle', array('class' => 'dragAndDropHandle'));
         // our JS needs to know an id, so we can send the new order
         $dataGrid->setRowAttributes(array('id' => '[id]'));
         // add datagrid to list
         $this->dataGrids[] = array('id' => $category['id'], 'name' => $category['name'], 'content' => $dataGrid->getContent());
     }
 }
Exemplo n.º 12
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $this->frm->cleanupFields();
         // redefine fields
         $fileFile = $this->frm->getField('file');
         $chkOverwrite = $this->frm->getField('overwrite');
         // name checks
         if ($fileFile->isFilled(BL::err('FieldIsRequired'))) {
             // only xml files allowed
             if ($fileFile->isAllowedExtension(array('xml'), sprintf(BL::getError('ExtensionNotAllowed'), 'xml'))) {
                 // load xml
                 $xml = @simplexml_load_file($fileFile->getTempFileName());
                 // invalid xml
                 if ($xml === false) {
                     $fileFile->addError(BL::getError('InvalidXML'));
                 }
             }
         }
         if ($this->frm->isCorrect()) {
             // import
             $statistics = BackendLocaleModel::importXML($xml, $chkOverwrite->getValue());
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_import', array('statistics' => $statistics));
             // everything is imported, so redirect to the overview
             $this->redirect(BackendModel::createURLForAction('index') . '&report=imported&var=' . ($statistics['imported'] . '/' . $statistics['total']) . $this->filterQuery);
         }
     }
 }
Exemplo n.º 13
0
 /**
  * Execute the action
  */
 public function execute()
 {
     parent::execute();
     // get parameters
     $categoryTitle = trim(SpoonFilter::getPostValue('value', null, '', 'string'));
     // validate
     if ($categoryTitle === '') {
         $this->output(self::BAD_REQUEST, null, BL::err('TitleIsRequired'));
     }
     // get the data
     // build array
     $item['title'] = SpoonFilter::htmlspecialchars($categoryTitle);
     $item['language'] = BL::getWorkingLanguage();
     $meta['keywords'] = $item['title'];
     $meta['keywords_overwrite'] = 'N';
     $meta['description'] = $item['title'];
     $meta['description_overwrite'] = 'N';
     $meta['title'] = $item['title'];
     $meta['title_overwrite'] = 'N';
     $meta['url'] = BackendBlogModel::getURLForCategory(SpoonFilter::urlise($item['title']));
     // update
     $item['id'] = BackendBlogModel::insertCategory($item, $meta);
     // output
     $this->output(self::OK, $item, vsprintf(BL::msg('AddedCategory'), array($item['title'])));
 }
Exemplo n.º 14
0
 /**
  * Validate the form
  *
  * @return	void
  */
 private function validateForm()
 {
     // is the form submitted?
     if ($this->frm->isSubmitted()) {
         // cleanup the submitted fields, ignore fields that were added by hackers
         $this->frm->cleanupFields();
         // validate field
         $this->frm->getField('synonym')->isFilled(BL::err('SynonymIsRequired'));
         $this->frm->getField('term')->isFilled(BL::err('TermIsRequired'));
         if (BackendSearchModel::existsSynonymByTerm($this->frm->getField('term')->getValue())) {
             $this->frm->getField('term')->addError(BL::err('TermExists'));
         }
         // no errors?
         if ($this->frm->isCorrect()) {
             // build item
             $item = array();
             $item['term'] = $this->frm->getField('term')->getValue();
             $item['synonym'] = $this->frm->getField('synonym')->getValue();
             $item['language'] = BL::getWorkingLanguage();
             // insert the item
             $id = BackendSearchModel::insertSynonym($item);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_add_synonym', array('item' => $item));
             // everything is saved, so redirect to the overview
             $this->redirect(BackendModel::createURLForAction('synonyms') . '&report=added-synonym&var=' . urlencode($item['term']) . '&highlight=row-' . $id);
         }
     }
 }
Exemplo n.º 15
0
 private function validateForm()
 {
     if ($this->form->isSubmitted()) {
         $fields = $this->form->getFields();
         if (!$fields['start_date']->isFilled(Language::err('FieldIsRequired')) || !$fields['end_date']->isFilled(Language::err('FieldIsRequired'))) {
             return;
         }
         if (!$fields['start_date']->isValid(Language::err('DateIsInvalid')) || !$fields['end_date']->isValid(Language::err('DateIsInvalid'))) {
             return;
         }
         $newStartDate = Model::getUTCTimestamp($fields['start_date']);
         $newEndDate = Model::getUTCTimestamp($fields['end_date']);
         // startdate cannot be before 2005 (earliest valid google startdate)
         if ($newStartDate < mktime(0, 0, 0, 1, 1, 2005)) {
             $fields['start_date']->setError(BL::err('DateRangeIsInvalid'));
         }
         // enddate cannot be in the future
         if ($newEndDate > time()) {
             $fields['start_date']->setError(BL::err('DateRangeIsInvalid'));
         }
         // enddate cannot be before the startdate
         if ($newStartDate > $newEndDate) {
             $fields['start_date']->setError(BL::err('DateRangeIsInvalid'));
         }
         if ($this->form->isCorrect()) {
             $this->startDate = $newStartDate;
             $this->endDate = $newEndDate;
         }
     }
 }
Exemplo n.º 16
0
 /**
  * Execute the action
  *
  * @return	void
  */
 public function execute()
 {
     // call parent, this will probably add some general CSS/JS or other required files
     parent::execute();
     // get parameters
     $id = SpoonFilter::getPostValue('id', null, 0, 'int');
     $tag = trim(SpoonFilter::getPostValue('value', null, '', 'string'));
     // validate
     if ($id === 0) {
         $this->output(self::BAD_REQUEST, null, 'no id provided');
     }
     if ($tag === '') {
         $this->output(self::BAD_REQUEST, null, BL::err('NameIsRequired'));
     }
     // check if tag exists
     if (BackendTagsModel::existsTag($tag)) {
         $this->output(self::BAD_REQUEST, null, BL::err('TagAlreadyExists'));
     }
     // build array
     $item['id'] = $id;
     $item['tag'] = SpoonFilter::htmlspecialchars($tag);
     $item['url'] = BackendTagsModel::getURL($item['tag'], $id);
     // update
     BackendTagsModel::update($item);
     // output
     $this->output(self::OK, $item, vsprintf(BL::msg('Edited'), array($item['tag'])));
 }
Exemplo n.º 17
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     // is the form submitted?
     if ($this->frm->isSubmitted()) {
         // cleanup the submitted fields, ignore fields that were added by hackers
         $this->frm->cleanupFields();
         // shorten fields
         $txtName = $this->frm->getField('name');
         $rbtDefaultForLanguage = $this->frm->getField('default');
         // validate fields
         if ($txtName->isFilled(BL::err('NameIsRequired'))) {
             // check if the group exists by name
             if (BackendMailmotorModel::existsGroupByName($txtName->getValue())) {
                 $txtName->addError(BL::err('GroupAlreadyExists'));
             }
         }
         // no errors?
         if ($this->frm->isCorrect()) {
             // build item
             $item['name'] = $txtName->getValue();
             $item['created_on'] = BackendModel::getUTCDate('Y-m-d H:i:s');
             $item['language'] = $rbtDefaultForLanguage->getValue() === '0' ? null : $rbtDefaultForLanguage->getValue();
             $item['is_default'] = $rbtDefaultForLanguage->getChecked() ? 'Y' : 'N';
             // insert the item
             $item['id'] = BackendMailmotorCMHelper::insertGroup($item);
             // check if all default groups were set
             BackendMailmotorModel::checkDefaultGroups();
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_add_group', array('item' => $item));
             // everything is saved, so redirect to the overview
             $this->redirect(BackendModel::createURLForAction('groups') . '&report=added&var=' . urlencode($item['name']) . '&highlight=id-' . $item['id']);
         }
     }
 }
Exemplo n.º 18
0
 /**
  * Loads the dataGrids
  */
 private function loadDatagrids()
 {
     // load all categories
     $categories = BackendFaqModel::getCategories(true);
     // loop categories and create a dataGrid for each one
     foreach ($categories as $categoryId => $categoryTitle) {
         $dataGrid = new BackendDataGridDB(BackendFaqModel::QRY_DATAGRID_BROWSE, array(BL::getWorkingLanguage(), $categoryId));
         $dataGrid->setAttributes(array('class' => 'dataGrid sequenceByDragAndDrop'));
         $dataGrid->setColumnsHidden(array('category_id', 'sequence'));
         $dataGrid->addColumn('dragAndDropHandle', null, '<span>' . BL::lbl('Move') . '</span>');
         $dataGrid->setColumnsSequence('dragAndDropHandle');
         $dataGrid->setColumnAttributes('question', array('class' => 'title'));
         $dataGrid->setColumnAttributes('dragAndDropHandle', array('class' => 'dragAndDropHandle'));
         $dataGrid->setRowAttributes(array('id' => '[id]'));
         // check if this action is allowed
         if (BackendAuthentication::isAllowedAction('edit')) {
             $dataGrid->setColumnURL('question', BackendModel::createURLForAction('edit') . '&amp;id=[id]');
             $dataGrid->addColumn('edit', null, BL::lbl('Edit'), BackendModel::createURLForAction('edit') . '&amp;id=[id]', BL::lbl('Edit'));
         }
         // add dataGrid to list
         $this->dataGrids[] = array('id' => $categoryId, 'title' => $categoryTitle, 'content' => $dataGrid->getContent());
     }
     // set empty datagrid
     $this->emptyDatagrid = new BackendDataGridArray(array(array('dragAndDropHandle' => '', 'question' => BL::msg('NoQuestionInCategory'), 'edit' => '')));
     $this->emptyDatagrid->setAttributes(array('class' => 'dataGrid sequenceByDragAndDrop emptyGrid'));
     $this->emptyDatagrid->setHeaderLabels(array('edit' => null, 'dragAndDropHandle' => null));
 }
Exemplo n.º 19
0
 /**
  * Parses the data to make the chart with
  */
 private function parseChartData()
 {
     $maxYAxis = 2;
     $metrics = array('visitors', 'pageviews');
     $graphData = array();
     $metricsPerDay = BackendAnalyticsModel::getMetricsPerDay($metrics, $this->startTimestamp, $this->endTimestamp);
     foreach ($metrics as $i => $metric) {
         $graphData[$i] = array();
         $graphData[$i]['title'] = $metric;
         $graphData[$i]['label'] = SpoonFilter::ucfirst(BL::lbl(SpoonFilter::toCamelCase($metric)));
         $graphData[$i]['i'] = $i + 1;
         $graphData[$i]['data'] = array();
         foreach ($metricsPerDay as $j => $data) {
             // cast SimpleXMLElement to array
             $data = (array) $data;
             // build array
             $graphData[$i]['data'][$j]['date'] = (int) $data['timestamp'];
             $graphData[$i]['data'][$j]['value'] = (string) $data[$metric];
         }
     }
     // loop the metrics
     foreach ($graphData as $metric) {
         foreach ($metric['data'] as $data) {
             // get the maximum value
             if ((int) $data['value'] > $maxYAxis) {
                 $maxYAxis = (int) $data['value'];
             }
         }
     }
     $this->tpl->assign('maxYAxis', $maxYAxis);
     $this->tpl->assign('tickInterval', $maxYAxis == 2 ? '1' : '');
     $this->tpl->assign('graphData', $graphData);
 }
Exemplo n.º 20
0
 /**
  * Calculate time ago.
  *
  * @return	string
  * @param	int $timestamp		Unix timestamp from the past.
  */
 public static function calculateTimeAgo($timestamp)
 {
     // calculate difference
     $secondsBetween = time() - $timestamp;
     // calculate
     $hours = floor($secondsBetween / (60 * 60));
     $minutes = floor($secondsBetween / 60);
     $seconds = floor($secondsBetween);
     // today start
     $todayStart = (int) strtotime(date('d F Y'));
     // today
     if ($timestamp >= $todayStart) {
         // today
         if ($hours >= 1) {
             return BL::getLabel('Today') . ' ' . date('H:i', $timestamp);
         } elseif ($minutes > 1) {
             return sprintf(BL::getLabel('MinutesAgo'), $minutes);
         } elseif ($minutes == 1) {
             return BL::getLabel('OneMinuteAgo');
         } elseif ($seconds > 1) {
             return sprintf(BL::getLabel('SecondsAgo'), $seconds);
         } elseif ($seconds <= 1) {
             return BL::getLabel('OneSecondAgo');
         }
     } elseif ($timestamp < $todayStart && $timestamp >= $todayStart - 86400) {
         return BL::getLabel('Yesterday') . ' ' . date('H:i', $timestamp);
     } else {
         return date('d/m/Y H:i', $timestamp);
     }
 }
Exemplo n.º 21
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     // is the form submitted?
     if ($this->frm->isSubmitted()) {
         // cleanup the submitted fields, ignore fields that were added by hackers
         $this->frm->cleanupFields();
         // shorten fields
         $txtName = $this->frm->getField('name');
         // validate fields
         if ($txtName->isFilled(BL::err('NameIsRequired'))) {
             if ($txtName->getValue() != $this->record['name'] && BackendMailmotorModel::existsCampaignByName($txtName->getValue())) {
                 $txtName->addError(BL::err('CampaignExists'));
             }
         }
         // no errors?
         if ($this->frm->isCorrect()) {
             // build item
             $item['id'] = $this->id;
             $item['name'] = $txtName->getValue();
             $item['created_on'] = BackendModel::getUTCDate('Y-m-d H:i:s');
             // update the item
             BackendMailmotorModel::updateCampaign($item);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_edit_campaign', array('item' => $item));
             // everything is saved, so redirect to the overview
             $this->redirect(BackendModel::createURLForAction('campaigns') . '&report=edited&var=' . urlencode($item['name']) . '&highlight=id-' . $item['id']);
         }
     }
 }
Exemplo n.º 22
0
 /**
  * Parses the data to make the line chart
  *
  * @param array $metricsPerDay All needed metrics grouped by day.
  */
 private function parseLineChartData($metricsPerDay)
 {
     $maxYAxis = 2;
     $metrics = array('pageviews');
     $graphData = array();
     foreach ($metrics as $i => $metric) {
         // build graph data array
         $graphData[$i] = array();
         $graphData[$i]['title'] = $metric;
         $graphData[$i]['label'] = SpoonFilter::ucfirst(BL::lbl(SpoonFilter::toCamelCase($metric)));
         $graphData[$i]['data'] = array();
         foreach ($metricsPerDay as $j => $data) {
             // cast SimpleXMLElement to array
             $data = (array) $data;
             $graphData[$i]['data'][$j]['date'] = (int) $data['timestamp'];
             $graphData[$i]['data'][$j]['value'] = (string) $data[$metric];
         }
     }
     // loop the metrics
     foreach ($graphData as $metric) {
         foreach ($metric['data'] as $data) {
             // get the maximum value
             if ((int) $data['value'] > $maxYAxis) {
                 $maxYAxis = (int) $data['value'];
             }
         }
     }
     $this->tpl->assign('maxYAxis', $maxYAxis);
     $this->tpl->assign('tickInterval', $maxYAxis == 2 ? '1' : '');
     $this->tpl->assign('lineGraphData', $graphData);
 }
Exemplo n.º 23
0
 /**
  * Parse this page
  *
  * @return	void
  */
 protected function parse()
 {
     // call parent parse
     parent::parse();
     // get results
     $results = BackendAnalyticsModel::getLandingPages($this->startTimestamp, $this->endTimestamp);
     // there are some results
     if (!empty($results)) {
         // get the datagrid
         $dataGrid = new BackendDataGridArray($results);
         // hide columns
         $dataGrid->setColumnsHidden('start_date', 'end_date', 'updated_on', 'page_encoded');
         // set headers values
         $headers['page_path'] = ucfirst(BL::lbl('Page'));
         // set headers
         $dataGrid->setHeaderLabels($headers);
         // set url
         $dataGrid->setColumnURL('page_path', BackendModel::createURLForAction('detail_page') . '&amp;page=[page_encoded]');
         // add the multicheckbox column
         $dataGrid->setMassActionCheckboxes('checkbox', '[id]');
         // add mass action dropdown
         $ddmMassAction = new SpoonFormDropdown('action', array('delete_landing_page' => BL::lbl('Delete')), 'delete');
         $dataGrid->setMassAction($ddmMassAction);
         // parse the datagrid
         $this->tpl->assign('dgPages', $dataGrid->getContent());
     }
 }
Exemplo n.º 24
0
 /**
  * Execute the action
  *
  * @return	void
  */
 public function execute()
 {
     // call parent
     parent::execute();
     // get parameters
     $id = SpoonFilter::getPostValue('id', null, 0, 'int');
     $droppedOn = SpoonFilter::getPostValue('dropped_on', null, -1, 'int');
     $typeOfDrop = SpoonFilter::getPostValue('type', null, '');
     // validate
     if ($id === 0) {
         $this->output(self::BAD_REQUEST, null, 'no id provided');
     }
     if ($droppedOn === -1) {
         $this->output(self::BAD_REQUEST, null, 'no id provided');
     }
     if ($typeOfDrop == '') {
         $this->output(self::BAD_REQUEST, null, 'no type provided');
     }
     // get page
     $success = BackendPagesModel::move($id, $droppedOn, $typeOfDrop);
     // build cache
     BackendPagesModel::buildCache(BL::getWorkingLanguage());
     // output
     if ($success) {
         $this->output(self::OK, BackendPagesModel::get($id), 'page moved');
     } else {
         $this->output(self::ERROR, null, 'page not moved');
     }
 }
Exemplo n.º 25
0
 /**
  * Parse into template
  */
 private function parse()
 {
     // get the logged in user
     $authenticatedUser = BackendAuthentication::getUser();
     // check if we need to show the password strength and parse the label
     $this->tpl->assign('showPasswordStrength', $authenticatedUser->getSetting('password_strength') !== 'strong');
     $this->tpl->assign('passwordStrengthLabel', BL::lbl($authenticatedUser->getSetting('password_strength')));
 }
Exemplo n.º 26
0
 /**
  * Load the datagrids
  *
  * @return	void
  */
 private function loadDataGrid()
 {
     // create datagrid
     $this->dataGrid = new BackendDataGridDB(BackendPagesModel::QRY_BROWSE_TEMPLATES, array($this->selectedTheme));
     // set colum URLs
     $this->dataGrid->setColumnURL('title', BackendModel::createURLForAction('edit_template') . '&amp;id=[id]');
     // add edit column
     $this->dataGrid->addColumn('edit', null, BL::lbl('Edit'), BackendModel::createURLForAction('edit_template') . '&amp;id=[id]', BL::lbl('Edit'));
 }
Exemplo n.º 27
0
 /**
  * Sets a link to the campaign statistics if it contains sent mailings
  *
  * @param int $id The ID of the campaign.
  * @return string
  */
 public static function setStatisticsLink($id)
 {
     // build the link HTML
     $html = '<a href="' . BackendModel::createURLForAction('statistics_campaign') . '&amp;id=' . $id . '" class="button icon iconStats linkButton"><span>' . BL::lbl('Statistics') . '</span></a>';
     // check if this campaign has sent mailings
     $hasSentMailings = BackendMailmotorModel::existsSentMailingsByCampaignID($id) > 0 ? true : false;
     // return the result
     return $hasSentMailings ? $html : '';
 }
Exemplo n.º 28
0
 /**
  * Execute the action
  *
  * @return	void
  */
 public function execute()
 {
     // call parent, this will probably add some general CSS/JS or other required files
     parent::execute();
     // get parameters
     $newSequence = SpoonFilter::getPostValue('new_sequence', null, '');
     // validate
     if ($newSequence == '') {
         $this->output(self::BAD_REQUEST, null, 'no new_sequence provided');
     }
     // convert into array
     $json = @json_decode($newSequence, true);
     // validate
     if ($json === false) {
         $this->output(self::BAD_REQUEST, null, 'invalid new_sequence provided');
     }
     // initialize
     $userSequence = array();
     $hiddenItems = array();
     // loop columns
     foreach ($json as $column => $widgets) {
         $columnValue = 'left';
         if ($column == 1) {
             $columnValue = 'middle';
         }
         if ($column == 2) {
             $columnValue = 'right';
         }
         // loop widgets
         foreach ($widgets as $sequence => $widget) {
             // store position
             $userSequence[$widget['module']][$widget['widget']] = array('column' => $columnValue, 'position' => $sequence, 'hidden' => $widget['hidden'], 'present' => $widget['present']);
             // add to array
             if ($widget['hidden']) {
                 $hiddenItems[] = $widget['module'] . '_' . $widget['widget'];
             }
         }
     }
     // get previous setting
     $currentSetting = BackendAuthentication::getUser()->getSetting('dashboard_sequence');
     $data['reload'] = false;
     // any settings?
     if ($currentSetting !== null) {
         // loop modules
         foreach ($currentSetting as $module => $widgets) {
             foreach ($widgets as $widget => $values) {
                 if ($values['hidden'] && isset($userSequence[$module][$widget]['hidden']) && !$userSequence[$module][$widget]['hidden']) {
                     $data['reload'] = true;
                 }
             }
         }
     }
     // store
     BackendAuthentication::getUser()->setSetting('dashboard_sequence', $userSequence);
     // output
     $this->output(self::OK, $data, BL::msg('Saved'));
 }
Exemplo n.º 29
0
 /**
  * Loads the settings form
  */
 private function loadForm()
 {
     $this->frm = new BackendForm('settings');
     // add map info (widgets)
     $this->frm->addDropdown('zoom_level_widget', array_combine(array_merge(array('auto'), range(3, 18)), array_merge(array(BL::lbl('Auto', $this->getModule())), range(3, 18))), BackendModel::getModuleSetting($this->URL->getModule(), 'zoom_level_widget', 13));
     $this->frm->addText('width_widget', BackendModel::getModuleSetting($this->URL->getModule(), 'width_widget'));
     $this->frm->addText('height_widget', BackendModel::getModuleSetting($this->URL->getModule(), 'height_widget'));
     $this->frm->addDropdown('map_type_widget', array('ROADMAP' => BL::lbl('Roadmap', $this->getModule()), 'SATELLITE' => BL::lbl('Satellite', $this->getModule()), 'HYBRID' => BL::lbl('Hybrid', $this->getModule()), 'TERRAIN' => BL::lbl('Terrain', $this->getModule())), BackendModel::getModuleSetting($this->URL->getModule(), 'map_type_widget', 'roadmap'));
 }
Exemplo n.º 30
0
 /**
  * Execute the action
  *
  * @return	void
  */
 public function execute()
 {
     // call parent, this will probably add some general CSS/JS or other required files
     parent::execute();
     // user is god?
     $isGod = BackendAuthentication::getUser()->isGod();
     // get possible languages
     if ($isGod) {
         $possibleLanguages = array_unique(array_merge(BL::getWorkingLanguages(), BL::getInterfaceLanguages()));
     } else {
         $possibleLanguages = BL::getWorkingLanguages();
     }
     // get parameters
     $language = SpoonFilter::getPostValue('language', array_keys($possibleLanguages), null, 'string');
     $module = SpoonFilter::getPostValue('module', BackendModel::getModules(false), null, 'string');
     $name = SpoonFilter::getPostValue('name', null, null, 'string');
     $type = SpoonFilter::getPostValue('type', BackendModel::getDB()->getEnumValues('locale', 'type'), null, 'string');
     $application = SpoonFilter::getPostValue('application', array('backend', 'frontend'), null, 'string');
     $value = SpoonFilter::getPostValue('value', null, null, 'string');
     // validate values
     if (trim($value) == '' || $language == '' || $module == '' || $type == '' || $application == '' || $application == 'frontend' && $module != 'core') {
         $error = BL::err('InvalidValue');
     }
     // in case this is a 'act' type, there are special rules concerning possible values
     if ($type == 'act' && !isset($error)) {
         if (!SpoonFilter::isValidAgainstRegexp('|^([a-z0-9\\-\\_])+$|', $value)) {
             $error = BL::err('InvalidActionValue', $this->getModule());
         }
     }
     // no error?
     if (!isset($error)) {
         // build item
         $item['language'] = $language;
         $item['module'] = $module;
         $item['name'] = $name;
         $item['type'] = $type;
         $item['application'] = $application;
         $item['value'] = $value;
         $item['edited_on'] = BackendModel::getUTCDate();
         $item['user_id'] = BackendAuthentication::getUser()->getUserId();
         // does the translation exist?
         if (BackendLocaleModel::existsByName($name, $type, $module, $language, $application)) {
             // add the id to the item
             $item['id'] = (int) BackendLocaleModel::getByName($name, $type, $module, $language, $application);
             // update in db
             BackendLocaleModel::update($item);
         } else {
             // insert in db
             BackendLocaleModel::insert($item);
         }
         // output OK
         $this->output(self::OK);
     } else {
         $this->output(self::ERROR, null, $error);
     }
 }