public function delete($id) { $id = (int) $id; $this->load->model('Campaign'); $result = Campaign::delete($id); if ($result === true) { redirect('/Campaign/view_all'); } elseif ($result instanceof Standard_error) { $this->layout->add_basic_assets()->menu()->view('others/form_failure', array('message' => $result->message)); } }
function admindeleteAction() { $this->view->title = "Delete Campaign"; if ($this->_request->isPost()) { $id = (int) $this->_request->getPost('id'); $del = $this->_request->getPost('del'); if ($del == 'Yes' && $id > 0) { $campaignModel = new Campaign(); $where = 'id = ' . $id; $campaignModel->delete($where); } $this->_redirect('campaign/adminindex'); } else { $id = (int) $this->_request->getParam('id'); if ($id > 0) { $campaignModel = new Campaign(); $this->view->campaign = $campaignModel->fetchRow('id=' . $id); } } }
function getAdminInterface() { $this->addJS('/modules/Campaigns/js/voteadmin.js'); $this->addCSS('/modules/Campaigns/css/campaign.css'); switch (@$_REQUEST['section']) { case 'addedit': if ($this->user->hasPerm('addcampaign')) { $campaign = new Campaign(@$_REQUEST['campaign_id']); $form = $campaign->getAddEditForm(); $this->smarty->assign('form', $form); $this->smarty->assign('status', $campaign->getId()); if ($form->isSubmitted() && isset($_REQUEST['submit'])) { if ($form->validate()) { return $this->topLevelAdmin(); } } return $this->smarty->fetch('admin/campaigns_addedit.tpl'); } return $this->smarty->fetch('../../../cms/templates/error.tpl'); case 'campaigndelete': $campaign = new Campaign($_REQUEST['campaign_id']); if ($this->user->hasPerm('addcampaign') && $this->user->getAuthGroup() == $campaign->getGroup() && strpos($campaign->getStatus(), 'pcoming') > 0) { $campaign->delete(); unset($campaign); return $this->topLevelAdmin(); } return $this->smarty->fetch('../../../cms/templates/error.tpl'); case 'viewresults': if ($this->user->hasPerm('viewcampaign')) { $campaign = new Campaign($_REQUEST['campaign_id']); $this->smarty->assign('campaign', $campaign); $campaign->addResultViewer($this->user->getId()); return $this->smarty->fetch('admin/campaign_results.tpl'); } return $this->smarty->fetch('admin/campaign_recips_addedit.tpl'); case 'questionedit': if ($this->user->hasPerm('addcampaign')) { $campaign = new Campaign($_REQUEST['campaign_id']); $this->smarty->assign('campaign', $campaign); if (isset($_REQUEST['choices_submit'])) { if (!is_null(@$_REQUEST['choice'])) { foreach ($_REQUEST['choice'] as $key => $achoice) { if (is_numeric($key)) { $choice = new CampaignChoice($key); if (!empty($achoice['main'])) { $choice->setCampaign($_REQUEST['campaign_id']); $choice->setChoice($achoice['main']); $choice->save(); if (is_array(@$_REQUEST['choice'][$key])) { $choice->createChildren($_REQUEST['choice'][$key]); } } else { $choice->delete(); } } } } if (!is_null(@$_REQUEST['nChoice'])) { if (isset($_REQUEST['nChoice'])) { foreach ($_REQUEST['nChoice'] as $key => $achoice) { if (!empty($achoice['main'])) { $choice = new CampaignChoice(); $choice->setCampaign($_REQUEST['campaign_id']); $choice->setChoice($achoice['main']); $choice->save(); if (is_array(@$_REQUEST['nChoice'][$key])) { $choice->createChildren($_REQUEST['nChoice'][$key]); } } } } } return $this->topLevelAdmin(); } return $this->smarty->fetch('admin/campaign_choices_addedit.tpl'); } return $this->smarty->fetch('../../../cms/templates/error.tpl'); case 'reciplist': return $this->recipTopLevelAdmin(); case 'recipaddedit': if ($this->user->hasPerm('addcampaignrecips')) { if (!is_null(@$_REQUEST['recipient_id'])) { $recipient = new CampaignUser($_REQUEST['recipient_id']); } else { $recipient = new CampaignUser(); $recipient->setGroup($this->user->getAuthGroup()); } $form = $recipient->getAddEditForm(); $this->smarty->assign('form', $form); if ($form->isSubmitted() && isset($_REQUEST['submit'])) { if ($form->validate()) { return $this->recipTopLevelAdmin(); } } return $this->smarty->fetch('admin/campaign_recips_addedit.tpl'); } return $this->smarty->fetch('../../../cms/templates/error.tpl'); case 'recipcsvup': if ($this->user->hasPerm('addcampaignrecips')) { $form = Campaign::getCSVForm(); $this->smarty->assign('form', $form); if ($form->validate() && $form->isSubmitted() && $_POST['submit']) { return $this->recipTopLevelAdmin(); } return $this->smarty->fetch('admin/campaign_csvup.tpl'); } return $this->smarty->fetch('../../../cms/templates/error.tpl'); case 'recipdelete': if ($this->user->hasPerm('addcampaignrecips')) { if (!is_null($_REQUEST['id']) && CampaignUser::exists($_REQUEST['id'])) { $recipient = new CampaignUser($_REQUEST['id']); if ($recipient->getGroup() == $this->user->getAuthGroup()) { $recipient->delete(); unset($_REQUEST['id']); } else { return $this->smarty->fetch('../../../cms/templates/error.tpl'); } } return $this->recipTopLevelAdmin(); } return $this->smarty->fetch('../../../cms/templates/error.tpl'); case 'votesend': if ($this->user->hasPerm('addcampaignrecips')) { $campaign = new Campaign($_REQUEST['campaign_id']); return $campaign->mailOut('votes'); } return 'You do not have permission to perform this action.'; case 'voteprint': if ($this->user->hasPerm('generatereciplist')) { $campaign = new Campaign($_REQUEST['campaign_id']); $campaign->preparePdf(); } return $this->topLevelAdmin(); case 'resultsend': if ($this->user->hasPerm('addcampaignrecips')) { $campaign = new Campaign($_REQUEST['campaign_id']); return $campaign->mailOut('results'); } return 'You do not have permission to perform this action.'; case 'listbilling': if ($this->user->hasPerm('admin')) { $groups = Group::getGroups(); $this->smarty->assign('groups', $groups); return $this->smarty->fetch('admin/billing_list.tpl'); } case 'viewbilling': if ($this->user->hasPerm('admin')) { $group = new Group($_REQUEST['group_id']); $this->smarty->assign('group', $group); $campaigns = Campaign::getCampaigns($_REQUEST['group_id']); $campaignsSorted = array_merge($campaigns['upcoming'], $campaigns['progress'], $campaigns['ended']); $this->smarty->assign('campaigns', $campaignsSorted); return $this->smarty->fetch('admin/billing_view.tpl'); } case 'togglestatus': if ($this->user->hasPerm('admin')) { $group = new Group($_REQUEST['group_id']); if ($group->getStatus() > 0) { $group->setStatus(0); } else { $group->setStatus(1); } $group->save(); } $groups = Group::getGroups(); $this->smarty->assign('groups', $groups); return $this->smarty->fetch('admin/billing_list.tpl'); break; case 'whovoted': if ($this->user->hasPerm('addcampaign')) { $campaign = new Campaign($_REQUEST['campaign_id']); $this->smarty->assign('votedlist', $campaign->userVotedList()); $this->smarty->assign('notvotedlist', $campaign->userVotedList(false)); $this->smarty->assign('campaignName', $campaign->getName()); return $this->smarty->fetch('admin/voted_list.tpl'); } return $this->topLevelAdmin(); case 'archivecampaign': if ($this->user->hasPerm('addcampaign')) { $campaign = new Campaign($_REQUEST['campaign_id']); $campaign->setArchiveStatus(1); $campaign->save(); } return $this->topLevelAdmin(); case 'viewarchive': if ($this->user->hasPerm('viewcampaign')) { $campaigns = Campaign::getCampaigns($this->user->getAuthGroup(), 1, 'endDate ASC'); $this->smarty->assign('campaigns', $campaigns); $this->smarty->assign('company', $this->user->getAuthGroupName()); return $this->smarty->fetch('admin/campaign_archive.tpl'); } return $this->topLevelAdmin(); default: if ($this->user->hasPerm('admin') && !$this->user->hasPerm('viewcampaign')) { header("Location: /admin/Campaigns§ion=listbilling"); } return $this->topLevelAdmin(); } }
public function postProcess() { //ADD if (Tools::isSubmit('submitAddcampaign')) { parent::validateRules(); if (count($this->errors)) { return false; } // ADD WAY if (!($id_campaign = (int) Tools::getValue('id_campaign')) && empty($this->errors)) { $defaultLanguage = new Language((int) Configuration::get('PS_LANG_DEFAULT')); // Include voucher : // Create campaign : $campaign = new Campaign(); $campaign->name = Tools::getValue('name'); $campaign->email_tpl = Tools::getValue('email_tpl'); $campaign->execution_time_day = Tools::getValue('execution_time_day'); $campaign->execution_time_hour = Tools::getValue('execution_time_hour'); $campaign->voucher_prefix = Tools::getValue('voucher_prefix'); $campaign->voucher_amount = Tools::getValue('voucher_amount'); $campaign->voucher_amount_type = Tools::getValue('voucher_amount_type'); $campaign->voucher_day = Tools::getValue('voucher_day'); $campaign->active = Tools::getValue('active'); // Create email files : $path = _PS_ROOT_DIR_ . '/modules/superabandonedcart/mails/' . $defaultLanguage->iso_code . '/'; if (!file_exists($path)) { if (!mkdir($path, 0777, true)) { $this->errors[] = Tools::displayError('Mails directory could not be created. Please check system permissions'); } } $tpl_file_name = $campaign->getFileName('html'); // create html files $f = fopen($path . $tpl_file_name, 'w'); fwrite($f, $campaign->email_tpl); fwrite($f, PHP_EOL); fclose($f); $tpl_file_name = $campaign->getFileName('txt'); // create txt files $f = fopen($path . $tpl_file_name, 'w'); fwrite($f, strip_tags($campaign->email_tpl)); fwrite($f, PHP_EOL); fclose($f); if (!$campaign->save()) { $this->errors[] = Tools::displayError('An error has occurred: Can\'t save the current object'); } // UPDATE WAY } elseif ($id_campaign = Tools::getValue('id_campaign')) { $defaultLanguage = new Language((int) Configuration::get('PS_LANG_DEFAULT')); // Create campaign : $campaign = new Campaign($id_campaign); $campaign->name = Tools::getValue('name'); $campaign->email_tpl = Tools::getValue('email_tpl'); $campaign->execution_time_day = Tools::getValue('execution_time_day'); $campaign->execution_time_hour = Tools::getValue('execution_time_hour'); $campaign->voucher_prefix = Tools::getValue('voucher_prefix'); $campaign->voucher_amount = Tools::getValue('voucher_amount'); $campaign->voucher_amount_type = Tools::getValue('voucher_amount_type'); $campaign->voucher_day = Tools::getValue('voucher_day'); $campaign->active = Tools::getValue('active'); $path = _PS_ROOT_DIR_ . '/modules/superabandonedcart/mails/' . $defaultLanguage->iso_code . '/'; if (!file_exists($path)) { if (!mkdir($path, 0777, true)) { $this->errors[] = Tools::displayError('Mails directory could not be created. Please check system permissions'); } } $tpl_file_name = $campaign->getFileName('html'); // create html files $f = fopen($path . $tpl_file_name, 'w'); fwrite($f, $campaign->email_tpl); fwrite($f, PHP_EOL); fclose($f); $tpl_file_name = $campaign->getFileName('txt'); // create txt files $f = fopen($path . $tpl_file_name, 'w'); fwrite($f, strip_tags($campaign->email_tpl)); fwrite($f, PHP_EOL); fclose($f); if (!$campaign->save()) { $this->errors[] = Tools::displayError('An error has occurred: Can\'t save the current object'); } } } elseif (Tools::isSubmit('statuscampaign') && Tools::getValue($this->identifier)) { if ($this->tabAccess['edit'] === '1') { if (Validate::isLoadedObject($object = $this->loadObject())) { if ($object->toggleStatus()) { $identifier = (int) $object->id_parent ? '&id_campaign=' . (int) $object->id_parent : ''; Tools::redirectAdmin($this->context->link->getAdminLink('AdminSuperAbandonedCart')); } else { $this->errors[] = Tools::displayError('An error occurred while updating the status.'); } } else { $this->errors[] = Tools::displayError('An error occurred while updating the status for an object.') . ' <b>' . $this->table . '</b> ' . Tools::displayError('(cannot load object)'); } } else { $this->errors[] = Tools::displayError('You do not have permission to edit this.'); } } elseif (Tools::getIsset('deletecampaign') && Tools::getValue($this->identifier)) { $id_campaign = (int) Tools::getValue($this->identifier); $b = new Campaign($id_campaign); $b->delete(); unset($b); } elseif (Tools::getIsset('submitBulkenableSelectioncampaign') && Tools::getValue('campaignBox')) { $ids_banner_deleted = Tools::getValue('campaignBox'); // remove each banner foreach ($ids_banner_deleted as $id) { $b = new Campaign($id); $b->toggleStatus(); unset($b); } } elseif (Tools::getIsset('submitBulkdisableSelectioncampaign') && Tools::getValue('campaignBox')) { $ids_banner_deleted = Tools::getValue('campaignBox'); // remove each banner foreach ($ids_banner_deleted as $id) { $b = new Campaign($id); $b->toggleStatus(); unset($b); } } }
* and open the template in the editor. */ if (!defined('SU')) { die; } ini_set("display_errors", 1); error_reporting(E_ALL); include_once 'include/common.php'; $msg = ""; $error = ""; require_once realpath(dirname(__FILE__)) . '/../classes/dashboard/Campaign.php'; $campaign = new Campaign(); if (isset($_REQUEST['sub']) && $_REQUEST['sub'] == 'delete') { if (isset($_REQUEST['id'])) { $id = (int) $_REQUEST['id']; if ($campaign->delete($id)) { $msg = "Campaign deleted successfully"; } else { $error = "Error deleting campaign"; } } } $q = "SELECT * FROM campaigns"; $r = $db->Execute($q); $campaigns = $campaign->get_campaigns(); ?> <div class="row"> <div class="col-sm-4"> <ol class="breadcrumb bc-3"> <li> <a href="admin.php?act=dashboard"><i class="entypo-home"></i>Dashboard</a> </li> <li class="active"> <strong>Campaigns</strong> </li>
function deleteAction() { $id = AF::get($_POST, 'id', 0); $modelsID = explode(',', $id); $errors = FALSE; foreach ($modelsID as $id) { $model = new Campaign(); $model->model_uset_id = $this->user->user_id; if ($model->findByPk($id)) { // if beforeDelete() returns an error, indicate this to the user if (!$model->delete($id)) { $errors = TRUE; } } else { $errors = TRUE; } if ($model->getErrors()) { $errors = TRUE; } unset($model); } if (isset($_POST['ajax'])) { AF::setJsonHeaders('json'); if ($errors) { Message::echoJsonError(__('campaign_no_deleted')); } else { Message::echoJsonSuccess(__('campaign_deleted')); } } $this->redirect(); }