protected function createFilter() { $searchFields = $this->searchFields; $restrictionsFields = array(0 => array('campaign_id', 'aff_id')); if ($searchFields['campaign_id'] !== null || in_array('campaign_id', $restrictionsFields[0])) { $campaignsID = AF::userAccess()->getRestrictionSearchFields('campaign_id', $searchFields['campaign_id']); if ($campaignsID) { $where = self::$_msql->parse(" AND p.`campaign_id` IN (?a)", $campaignsID); $this->setwhere($where, 'campaign_id'); unset($campaignsID, $where); } } if (in_array('aff_id', $restrictionsFields[0])) { $IDs = AF::userAccess()->getRestrictionSearchFields('aff_id', array()); if ($IDs) { $where = self::$_msql->parse(" AND p.`aff_id` IN (?a)", $IDs); $this->setwhere($where, 'aff_id'); unset($IDs, $where); } } }
function cloneAction() { if (isset($_POST['clone'])) { $model = AFActiveDataProvider::models('Campaign'); $campaigns = $model->getCampaigns(); $campaigns = AF::userAccess()->array2RestrictionArray('campaign_id', $campaigns); AF::setJsonHeaders('json'); echo json_encode(array('campaigns' => $campaigns)); die; } if (isset($_POST['ajax'])) { AF::setJsonHeaders('json'); $campaign_id = AF::get($_POST, 'campaign_id', 0); $pixel_ids = AF::get($_POST, 'pixel_id', 0); if (AF::userAccess()->hasRestrictions('campaign_id')) { $rf = AF::userAccess()->getRestrictionSearchFields('campaign_id', array()); if (!in_array($campaign_id, $rf)) { Message::echoJsonError(__('pixel_not_cloned')); } } if (!$pixel_ids && !$campaign_id) { Message::echoJsonError(__('campaign_id_not_found')); } $pixels = explode(',', $pixel_ids); $message = array(); $newIDs = array(); $isMany = count($pixels) > 1 ? true : false; $isThisCampaign = true; foreach ($pixels as $pixel_id) { $model = new Pixel(); if (!$model->fillFromDbPk($pixel_id)) { if ($isMany) { continue; } Message::echoJsonError(__('pixel_not_found')); } if ($model->campaign_id != $campaign_id) { $model->campaign_id = $campaign_id; $isThisCampaign = false; } if (!$model->cloneModel()) { if ($isMany) { continue; } Message::echoJsonError(__('pixel_not_found')); } $newID = $newIDs[] = $model->getPkValue(); $message[] = __('pixel_cloned') . ' <a href="' . $this->controller . '/update/id=' . $newID . '">' . __('edit') . ' (ID: ' . $newID . ')</a><br>'; unset($model); } if (!$message) { Message::echoJsonError(__('pixel_not_cloned')); } $message = implode($message); $newIDs = implode(',', $newIDs); $v = array('message' => $message); if ($isThisCampaign) { $v['newid'] = $newIDs; } Message::echoJsonSuccess($v); } }
public function getnext_product_info_formatted() { if (!$this->next_product_id) { return ''; } if (!AF::userAccess()->actionAccess(array('products', 'update'))) { return '[' . $this->next_product_id . '] ' . $this->next_product_name; } $olink = AF::link(array('orders' => 'view'), array('product' => $this->next_product_id)); $plink = AF::link(array('products' => 'update'), array('id' => $this->next_product_id)); return '[<a title="Search Orders by Product ID" data-toggle="atooltip" href="' . $olink . '">' . $this->next_product_id . '</a>] <a title="View Product" data-toggle="atooltip" href="' . $plink . '">' . $this->next_product_name . '</a>'; }
?> </label> <div class="controls"> <select id="pixels_select_pixel_type" name="pixel_type" class="chosen-select select-xlarge" > <option value=""><?php echo __('choose'); ?> </option> <option value="postback" <?if('postback' == $model->pixel_type){?>selected=""<?}?>>postback</option> <option value="iframe" <?if('iframe' == $model->pixel_type){?>selected=""<?}?>>iframe</option> </select> <span class="help-inline"></span> </div> </div> <?$ff=AF::userAccess()->hasRestrictions('aff_id');?> <?if(!$ff){?> <div class="control-group"> <div class="controls"> <label class="checkbox"> <input id="afid_all_checked" type="checkbox" name="aff_id_ALL" value="1" <?if(!$model->aff_id){?>checked="yes"<?}?>> <?php echo __('all_afid'); ?> </label> <span class="help-inline"></span> </div> </div> <?}?> <div class="control-group <?if(!$model->aff_id && !$ff){?>hide<?}?>" id="div_afid_id" > <label class="control-label"><?php
public function getRCampaigns() { $where = $this->unsetWhereKey('c_campaign_id'); $sql = "SELECT op.`campaign_id`, c.`campaign_name`\n FROM `prospects` AS op\n JOIN `campaigns` AS c ON op.`campaign_id` = c.`campaign_id`\n\t\t\t\tLEFT JOIN profiles as pr USING(profile_id) {$this->join}\n\t\t\t\t/*LEFT JOIN gateways as g USING(gateway_id)*/\n WHERE ?p AND `prospect_id` IS NULL and c.attach != 1\n UNION\n SELECT op.`campaign_id`, c.`campaign_name`\n FROM `orders` AS op\n JOIN `campaigns` AS c ON op.`campaign_id` = c.`campaign_id`\n LEFT JOIN profiles as pr USING(profile_id) {$this->join}\n\t\t\t\t/*LEFT JOIN gateways as g USING(gateway_id)*/\n WHERE ?p and c.attach != 1 AND op.`status` IN ('ok', 'sent', 'shipped', 'returned', 'void') AND op.`billing_cycle` = 0 AND FIND_IN_SET('test',`flags`)=0\n ORDER BY `campaign_id` DESC"; $result = self::$_msql->getAll($sql, $where, $where); return AF::userAccess()->array2RestrictionArray('campaign_id', $result); }
protected function createFilter() { $searchFields = $this->searchFields; $restrictionsFields = array(0 => array('campaign_id')); if ($searchFields['action'] !== null) { $statuses = explode(',', $searchFields['action']); $where = self::$_msql->parse(" AND l.`action` IN (?a)", $statuses); $this->setwhere($where, 'action'); unset($statuses, $where); } if ($searchFields['actions'] !== null) { $statuses = explode(',', $searchFields['actions']); $where = self::$_msql->parse(" AND ol.`action` IN (?a)", $statuses); $this->setwhere($where, 'actions'); unset($statuses, $where); } if ($searchFields['user_id'] !== null) { $where = self::$_msql->parse(" AND l.`user_id` = ?i", (int) $searchFields['user_id']); $this->setwhere($where, 'user_id'); unset($where); } if ($searchFields['r_user_id'] !== null) { $ids = explode(',', $searchFields['r_user_id']); $where = self::$_msql->parse(" AND ol.`user_id` IN (?a)", $ids); $this->setwhere($where, 'r_user_id'); unset($ids, $where); } if ($searchFields['order_id'] !== null) { $where = self::$_msql->parse(" AND l.`order_id` = ?i", (int) $searchFields['order_id']); $this->setwhere($where, 'order_id'); unset($where); } if ($searchFields['dates'] !== null) { $dates = explode('-', $searchFields['dates']); $dateStart = null; $dateFinish = null; if (isset($dates[0])) { $dateStartT = explode('.', $dates[0]); if (isset($dateStartT[0]) && isset($dateStartT[1]) && isset($dateStartT[2])) { $dateStart = array_reverse($dateStartT); $dateStart = implode('-', $dateStart) . ' 00:00:00'; $this->where = self::$_msql->parse(" AND l.`create` >= ?s", $dateStart); } } if (isset($dates[1])) { $dateStartT = explode('.', $dates[1]); if (isset($dateStartT[0]) && isset($dateStartT[1]) && isset($dateStartT[2])) { $dateFinish = array_reverse($dateStartT); $dateFinish = implode('-', $dateFinish) . ' 23:59:59'; $this->where = self::$_msql->parse(" AND l.`create` <= ?s", $dateFinish); $this->where = self::$_msql->parse(" AND l.`create` <= ?s", $dateFinish); } } unset($dateStartT, $dateStart, $dateFinish); } if ($searchFields['cr_dates'] !== null) { $dates = explode('-', $searchFields['cr_dates']); if (isset($dates[0]) && isset($dates[1])) { $dateStartT = explode('.', $dates[0]); $dateStart = array_reverse($dateStartT); $dateStart = implode('-', $dateStart); $dateFinishT = explode('.', $dates[1]); $dateFinish = array_reverse($dateFinishT); $dateFinish = implode('-', $dateFinish); $this->where = self::$_msql->parse(" AND DATE(ol.`create`) BETWEEN ?s AND ?s", $dateStart, $dateFinish); } unset($dateStartT, $dateFinishT); } if ($searchFields['ur_dates'] !== null) { $dates = explode('-', $searchFields['ur_dates']); if (isset($dates[0]) && isset($dates[1])) { $dateStartT = explode('.', $dates[0]); $dateStart = array_reverse($dateStartT); $dateStart = implode('-', $dateStart); $dateFinishT = explode('.', $dates[1]); $dateFinish = array_reverse($dateFinishT); $dateFinish = implode('-', $dateFinish); $this->where = self::$_msql->parse(" AND DATE(ol.`create`) BETWEEN ?s AND ?s", $dateStart, $dateFinish); } unset($dateStartT, $dateFinishT); } if ($searchFields['action_id'] !== null) { $action = explode(',', $searchFields['action_id']); $where = self::$_msql->parse(" AND ol.`action` IN (?a)", $action); $this->setwhere($where, 'action_id'); unset($action, $where); } if ($searchFields['gateway_id'] !== null) { $id = (int) $searchFields['gateway_id']; $where = self::$_msql->parse(" AND g.`gateway_id` = ?i", $id); $this->setwhere($where, 'gateway_id'); unset($id, $where); } if ($searchFields['campaign_id'] !== null || in_array('campaign_id', $restrictionsFields[0])) { $campaignsID = AF::userAccess()->getRestrictionSearchFields('campaign_id', $searchFields['campaign_id']); if ($campaignsID) { $where = self::$_msql->parse(" AND c.`campaign_id` IN (?a)", $campaignsID); $this->setwhere($where, 'campaign_id'); unset($campaignsID, $where); } } /* if( $searchFields['campaign_id'] !== null ) { $id = (int)$searchFields['campaign_id']; $where = self::$_msql->parse(" AND c.`campaign_id` = ?i", $id); $this->setwhere($where, 'campaign_id'); unset($id, $where); } */ unset($searchFields); }
protected static function createCustomFilter($params) { // Mysql connect $msql = SafeMySQL::getInstance(); $whereArray = array(); $joinArray = array(); $restrictionsFields = array(0 => array('campaign_id', 'aff_id')); // this is the search conditions if ($params['dates_post'] !== null) { $dates = explode('-', $params['dates_post']); if (isset($dates[0]) && isset($dates[1])) { $dateStartT = explode('.', $dates[0]); $dateStart = array_reverse($dateStartT); $dateStart = implode('-', $dateStart); $dateFinishT = explode('.', $dates[1]); $dateFinish = array_reverse($dateFinishT); $dateFinish = implode('-', $dateFinish); $whereArray['dates_post'] = $msql->parse("AND DATE(o.`created`) BETWEEN ?s AND ?s", $dateStart, $dateFinish); } unset($dateStartT, $dateFinishT); } if ($params['order_id'] !== null) { $ids = explode(',', $params['order_id']); $whereArray['order_id'] = $msql->parse("AND o.`order_id` IN(?a)", $ids); // if search by id, another search fields doesn't counted return self::returnSearchCreater($whereArray, $joinArray, array('order_id', 'page')); } if ($params['aff_id'] || in_array('aff_id', $restrictionsFields[0])) { $IDs = AF::userAccess()->getRestrictionSearchFields('aff_id', $params['aff_id']); if ($IDs) { $whereArray['aff_id'] = $msql->parse("AND o.`aff_id` IN (?a)", $IDs); } } if ($params['ip'] !== null) { $whereArray['ip'] = $msql->parse("AND o.`ip` = ?s", ip2long($params['ip'])); } if ($params['billing_cycle'] !== null) { $billingCycle = (int) $params['billing_cycle']; if ($billingCycle >= 0) { $whereArray['billing_cycle'] = $msql->parse("AND o.`billing_cycle` = ?i", $billingCycle); } } if ($params['tracking_number'] !== null) { $whereArray['tracking_number'] = $msql->parse("AND at.`tracking_number` = ?i", (int) $params['tracking_number']); $joinArray['attempts'] = "LEFT JOIN `attempts` as at USING(`order_id`)"; } if ($params['status']) { $whereArray['status'] = $msql->parse("AND o.`status` IN (?a)", $params['status']); } if ($params['campaign_id'] || in_array('campaign_id', $restrictionsFields[0])) { $campaignsID = AF::userAccess()->getRestrictionSearchFields('campaign_id', $params['campaign_id']); if ($campaignsID) { $whereArray['campaign_id'] = $msql->parse("AND o.`campaign_id` IN (?a)", $campaignsID); } } //Use in search by product $productSearchAndWhere = ''; if ($params['recurring_orders'] !== null) { $whereArray['recurring_orders'] = "AND o.`status` IN ('ok','sent','shipped')"; if ($params['product_id']) { $productSearchAndWhere = "AND FIND_IN_SET('recurring', `flags`)>0"; } else { $whereArray['product'] = "AND o.`order_id` IN (\n SELECT DISTINCT `order_id`\n FROM `orders_products`\n WHERE FIND_IN_SET('recurring', `flags`)>0\n )"; } } if ($params['pending_recurring'] !== null) { $whereArray['recurring_orders'] = "AND o.`status` IN ('ok','sent','shipped')"; if ($params['product_id']) { $productSearchAndWhere = "AND (FIND_IN_SET('recurring', `flags`)>0 and `recurring_next` >= now())"; } else { $whereArray['product'] = "AND o.`order_id` IN (\n SELECT DISTINCT `order_id`\n FROM `orders_products`\n WHERE FIND_IN_SET('recurring', `flags`)>0 and `recurring_next` >= now()\n )"; } } if ($params['product_id']) { $whereArray['product_id'] = $msql->parse("AND o.`order_id` IN (\n SELECT DISTINCT `order_id`\n \t FROM `orders_products`\n \t WHERE `product_id` IN (?a)\n \t {$productSearchAndWhere}\n )", $params['product_id']); } if ($params['country_id'] !== null) { $whereArray['country_id'] = $msql->parse("AND c.`country_id` = ?s", $params['country_id']); $joinArray['campaigns'] = "LEFT JOIN `campaigns` as c USING(`campaign_id`)"; } if ($params['method_id'] !== null) { $whereArray['method_id'] = $msql->parse("AND p.`method_id` = ?i", (int) $params['method_id']); $joinArray['payments'] = "LEFT JOIN `payments` as p USING(`payment_id`)"; } if ($params['num2'] !== null) { $whereArray['num2'] = $msql->parse("AND p.`num2` = ?i", (int) $params['num2']); $joinArray['payments'] = "LEFT JOIN `payments` as p USING(`payment_id`)"; } if ($params['num3'] !== null) { $whereArray['num3'] = $msql->parse("AND p.`num3` = ?i", (int) $params['num3']); $joinArray['payments'] = "LEFT JOIN `payments` as p USING(`payment_id`)"; } if ($params['pixel_fired'] !== null) { $whereArray['pixel_fired'] = "AND o.`pixel_fired` != 0"; } // Search By customer $customerSearchWhereArray = array(); $customerSearchJoinArray = array(); if ($params['customer_id'] !== null) { $customerSearchWhereArray[] = $msql->parse("AND `customer_id` = ?i", $params['customer_id']); } if ($params['email'] !== null) { $customerSearchWhereArray[] = $msql->parse("AND `email` LIKE ?s", '%' . $params['email'] . '%'); } if ($params['address_fname'] !== null) { $customerSearchWhereArray[] = $msql->parse("AND a.`fname` LIKE ?s", '%' . $params['address_fname'] . '%'); $customerSearchJoinArray['addresses'] = 'LEFT JOIN `addresses` AS a USING (`customer_id`)'; } if ($params['address_lname'] !== null) { $customerSearchWhereArray[] = $msql->parse("AND a.`lname` LIKE ?s", '%' . $params['address_lname'] . '%'); $customerSearchJoinArray['addresses'] = 'LEFT JOIN `addresses` AS a USING (`customer_id`)'; } if ($params['phone'] !== null) { $customerSearchWhereArray[] = $msql->parse("AND a.`phone` LIKE ?s", '%' . $params['phone'] . '%'); $customerSearchJoinArray['addresses'] = 'LEFT JOIN `addresses` AS a USING (`customer_id`)'; } if ($params['zip'] !== null) { $customerSearchWhereArray[] = $msql->parse("AND a.`zip` LIKE ?s", '%' . $params['zip'] . '%'); $customerSearchJoinArray['addresses'] = 'LEFT JOIN `addresses` AS a USING (`customer_id`)'; } if ($params['country'] !== null) { $customerSearchWhereArray[] = $msql->parse("AND a.`country_id` = ?s", $params['country']); $customerSearchJoinArray['addresses'] = 'LEFT JOIN `addresses` AS a USING (`customer_id`)'; } if ($params['state'] !== null) { $customerSearchWhereArray[] = $msql->parse("AND a.`state_id` = ?s", $params['state']); $customerSearchJoinArray['addresses'] = 'LEFT JOIN `addresses` AS a USING (`customer_id`)'; } if ($params['city'] !== null) { $customerSearchWhereArray[] = $msql->parse("AND a.`city` LIKE ?s", '%' . $params['city'] . '%'); $customerSearchJoinArray['addresses'] = 'LEFT JOIN `addresses` AS a USING (`customer_id`)'; } if ($params['address'] !== null) { $customerSearchWhereArray[] = $msql->parse("AND ( a.`address1` LIKE ?s OR a.`address2` LIKE ?s)", '%' . $params['address'] . '%', '%' . $params['address'] . '%'); $customerSearchJoinArray['addresses'] = 'LEFT JOIN `addresses` AS a USING (`customer_id`)'; } if ($customerSearchWhereArray) { $customerSearchJoin = $customerSearchJoinArray ? implode(' ', $customerSearchJoinArray) : ''; $customerSearchWhere = implode(' ', $customerSearchWhereArray); $sql = "AND o.`customer_id` IN\n (\n SELECT DISTINCT customer_id\n FROM customers\n {$customerSearchJoin}\n WHERE 1\n {$customerSearchWhere}\n )"; $whereArray['customer'] = $sql; } return self::returnSearchCreater($whereArray, $joinArray); }
public function getCampaignsCountOrdersR() { $where = $this->unsetWhereKey('campaign_id'); $unionSelect = ''; if (!empty($this->searchFields['campaign_id'])) { $tempArray = explode(',', $this->searchFields['campaign_id']); foreach ($tempArray as $value) { $unionSelect .= " UNION SELECT {$value},0"; } } $sql = "SELECT c.`url`,\n c.`campaign_id`,\n c.`campaign_name`,\n COUNT(DISTINCT c.`campaign_id`) as count\n FROM `orders` o\n JOIN `campaigns` as c ON c.`campaign_id` = o.`campaign_id`\n\t\t\t\tJOIN `profiles_gateways` as pg ON c.`profile_id` = pg.`profile_id`\n JOIN `gateways` as g ON pg.`gateway_id` = g.`gateway_id`\n WHERE ?p\n GROUP BY c.`campaign_id`\n ORDER BY c.`campaign_id` DESC"; $result = self::$_msql->getAll($sql, $where); return AF::userAccess()->array2RestrictionArray('campaign_id', $result); }
public function findAllInArray($turn = false) { $result = null; if ($this->isCache) { $cacheID = $this->modelName . '_get_all_in_array'; $result = AF::cache()->get($cacheID); } if (!$result) { // hack for Templates class if ($this->modelName == 'template') { $sql = "SELECT template_id, template_name, body_subject\n\t\t\t\t\tFROM ?n\n\t\t\t\t\tORDER BY ?s DESC"; } else { $sql = "SELECT *\n\t\t\t\t\tFROM ?n\n\t\t\t\t\tORDER BY ?s DESC"; } $pks = $this->getPrimaryField(); if (!is_array($pks)) { $pks = array($pks); } $resultTemp = self::$_msql->getAll($sql, $this->tableName(), implode(',', $pks)); $result = array(); foreach ($resultTemp as $item) { $keysArray = array(); foreach ($pks as $k) { $keysArray[] = $item[$k]; } $key = implode('_', $keysArray); $result[$key] = $item; } if ($this->isCache) { $data = serialize($result); if (strlen($data) < 1000000) { AF::cache()->set($cacheID, $result); } } } if ($this->_isRestrictions) { $pks = $this->getPrimaryField(); if (is_array($pks)) { $pks = implode('_', $pks); } $f = AF::userAccess()->getRestrictionBySearch($pks); if ($f) { foreach ($result as $k => $v) { if (!in_array($k, $f[$pks])) { unset($result[$k]); } } } } return $turn ? array_reverse($result) : $result; }
public function getCardTypeReportCampaigns() { $where = $this->unsetWhereKey('campaign_id'); $sql = "SELECT `o`.`campaign_id`, `c`.`campaign_name`\n FROM `orders` as `o`\n JOIN `payments` as `pn` USING (`payment_id`)\n JOIN `campaigns` as `c` USING (`campaign_id`)\n JOIN `gateways` as `g` ON `o`.`gateway_id` = `g`.`gateway_id`\n\t\t\t\tJOIN `systems` as s USING (`system_code`)\n WHERE ?p \n GROUP BY `o`.`campaign_id`\n ORDER BY `o`.`campaign_id` DESC"; //AND s.`system_code`='pn' //AND `p`.`shippable` > 0 $result = self::$_msql->getAll($sql, $where); return AF::userAccess()->array2RestrictionArray('campaign_id', $result); }