public function ajaxGetCampaignsAction()
 {
     $this->_helper->layout->disableLayout();
     $province = $this->_request->province;
     $district = $this->_request->district;
     $level = $this->_request->level;
     $campaigns = new Model_Campaigns();
     if ($level == 1) {
         $campaign_data = $campaigns->getAllCampaignsNational();
     } elseif ($level == 2) {
         $campaigns->form_values['province_id'] = $province;
         $campaign_data = $campaigns->getCampaignsByProvince();
     } elseif ($level == 6) {
         $campaigns->form_values['districts'] = $district;
         $campaign_data = $campaigns->getCampaignsByDistrictReports();
     } else {
         $campaign_data = $campaigns->getAllCampaigns();
     }
     $this->view->campaign_data = $campaign_data;
 }
 public function ajaxForCampaignAction()
 {
     $this->_helper->layout->disableLayout();
     $campaign_type_id = $this->_request->getParam('campaign_type_id', '');
     $item_id = $this->_request->getParam('item_id', $this->_request->getPost('item_id'));
     if ($item_id && is_array($item_id)) {
         $item_id = implode(',', $item_id);
     }
     $date_from = $this->_request->getParam('date_from', '');
     $date_to = $this->_request->getParam('date_to', '');
     $province_id = $this->_request->getParam('province_id', '');
     //$province_id = (!empty($province_id)) ? $province_id : $this->_identity->getProvinceId();
     $dist_id = $this->_request->getParam('dist_id', '');
     $campaign_id = $this->_request->getParam('campaign_id', '');
     $day = $this->_request->getParam('day', '');
     $wh_id = $this->_request->getParam('wh_id', '');
     $provinces = $this->_request->getParam('provinces', '');
     $district_id = $this->_request->getParam('district_id', '');
     $condition = $this->_request->getParam('condition', '');
     $show_all = $this->_request->getParam('show_all', '');
     $campaign = new Model_Campaigns();
     // Create Campaign Name
     if (!empty($campaign_type_id)) {
         $campaign->form_values['campaign_type_id'] = $campaign_type_id;
         $campaign->form_values['date_from'] = $date_from;
         $campaign->form_values['item_IDs'] = $item_id;
         //Get Product Names
         $pro_names = $campaign->getCampaignVccNames();
         //Get campaign type name
         $camp_type_name = $campaign->getCompaignTypeName();
         $campaign_name = $camp_type_name[0]['camapignTypeName'] . ' ' . $pro_names[0]['itemNames'] . ' ' . date('d M Y', strtotime(App_Controller_Functions::dateToDbFormat($date_from))) . '- ' . date('d M Y', strtotime(App_Controller_Functions::dateToDbFormat($date_to)));
         $this->view->condition = "001";
         $this->view->campaign_name = $campaign_name;
     }
     // Get districts of the selected province
     //if (!empty($province_id)) {
     if ($condition == "002") {
         $campaign->form_values['province_id'] = $province_id;
         $campaign->form_values['campaign_id'] = $campaign_id;
         $districts = $campaign->getCampaignDistricts();
         $this->view->condition = "002";
         $this->view->dist_id = $dist_id;
         $this->view->districts = $districts;
     }
     // Get Warehouses for the selected campaigns
     //if (!empty($campaign_id) && !empty($district_id) && !empty($day)) {
     if ($condition == "003") {
         $campaign->form_values['campaign_id'] = $campaign_id;
         $campaign->form_values['district_id'] = $district_id;
         $campaign->form_values['campaign_day'] = $day;
         $all_warehouses = $campaign->getCampaignUCsForDataEntry();
         $this->view->condition = "003";
         $this->view->wh_id = $wh_id;
         $this->view->all_warehouses = $all_warehouses;
     }
     // Show campaings for the selected District
     if (!empty($campaign_id) && !empty($district_id) && empty($day)) {
         $campaign->form_values['campaign_id'] = $campaign_id;
         $campaign->form_values['district_id'] = $district_id;
         $all_campaigns = $campaign->getAllCampaigns();
         $this->view->condition = "004";
         $this->view->campaign_id = $campaign_id;
         $this->view->all_campaigns = $all_campaigns;
     }
     // Show campaign items for the selected Campaign
     if ($condition == "005") {
         $campaign->form_values['campaign_id'] = $campaign_id;
         $campaign->form_values['item_id'] = $item_id;
         $all_campaigns = $campaign->campaignItems();
         $this->view->condition = "005";
         $this->view->item_id = $item_id;
         $this->view->campaign_id = $campaign_id;
         $this->view->all_campaigns = $all_campaigns;
     }
     // Get dates for the selected campaigns
     if ($condition == "006") {
         $campaign->form_values['campaign_id'] = $campaign_id;
         $campaign->form_values['campaign_day'] = $day;
         $campaign_days = $campaign->getCampaignDays();
         $catch_up_days = $campaign_days[0]['catchUpDays'] + 1;
         $end_date = date('Y-m-d', strtotime("{$catch_up_days} days", strtotime($campaign_days[0]['dateTo'])));
         $start_date = $campaign_days[0]['dateFrom'];
         $begin = new DateTime($start_date);
         $end = new DateTime($end_date);
         $diff = $begin->diff($end);
         $interval = DateInterval::createFromDateString('1 day');
         $period = new DatePeriod($begin, $interval, $end);
         $this->view->condition = "006";
         $this->view->day = $day;
         $this->view->show_all = $show_all;
         $this->view->period = $period;
     }
     // Get Provinces of the selected campaign
     //if (isset($province_id) && isset($campaign_id) && isset($provinces) && $provinces == 1) {
     if ($condition == "007") {
         $campaign->form_values['campaign_id'] = $campaign_id;
         $campaign->form_values['province_id'] = $province_id;
         $provinces = $campaign->getCampaignProvinces();
         $this->view->condition = "007";
         $this->view->province_id = $province_id;
         $this->view->provinces = $provinces;
     }
 }
 /**
  * Campaign Management Dashlet
  */
 public function differentMissedTypesAction()
 {
     $campaign = new Model_Campaigns();
     $this->view->campaigns = $campaign->getAllCampaigns();
     $wh_data = new Model_WarehousesData();
     $params["level"] = $this->_request->getParam("level");
     $params["loc_id"] = $this->_request->getParam("district");
     $params["prov_id"] = $this->_request->getParam("province");
     $params["camp"] = $this->_request->getParam('camp');
     $wh_data->form_values = $params;
     $xmlstore = $wh_data->differentMissedTypes();
     $this->view->xmlstore = $xmlstore;
     $this->view->camp = $params["camp"];
 }
 public function vlmisAction()
 {
     $salt = '159jboFHjeQK5mc1K0cdSz5';
     $token = sha1(md5($salt . date('Y-m-d')));
     if (!$this->_identity->login('userdashboard', base64_encode(123))) {
         $error = true;
         throw new Exception();
     }
     if ($token != $_GET['token']) {
         $this->view->message = 'Invalid Token';
     }
     $province = isset($_GET['combo1']) ? $_GET['combo1'] : 1;
     $level = isset($_GET['office']) ? $_GET['office'] : 1;
     $role_id = 4;
     $this->view->level = $level;
     $this->view->province = $province;
     $this->_helper->layout->setLayout('vlmis-dashboad');
     $auth = App_Auth::getInstance();
     //$role_id = $auth->getRoleId();
     $campaign = new Model_Campaigns();
     $location = new Model_Locations();
     $location->form_values = array('geo_level_id' => 4, 'province_id' => $province);
     $res = $location->getLocationsByLevelByProvince();
     $district = $res[0]['key'];
     $this->view->district = $district;
     switch ($level) {
         case 1:
             $this->view->campaigns = $campaign->getAllCampaigns();
             break;
         case 2:
             $location->form_values = array("province_id" => $province);
             $dists = $location->districtLocations();
             foreach ($dists as $dist) {
                 $arr_dist[] = $dist['pk_id'];
             }
             $campaign->form_values = array("districts" => implode(",", $arr_dist));
             $this->view->campaigns = $campaign->getCampaignsByDistrict();
             break;
         case 6:
             $campaign->form_values = array("districts" => $district);
             $this->view->campaigns = $campaign->getCampaignsByDistrict();
             break;
         default:
             $this->view->campaigns = $campaign->getAllCampaigns();
             break;
     }
     $this->view->provinces = $location->getProvincesName();
     $item = new Model_ItemPackSizes();
     $this->view->items = $item->getAllItemsByCategoryAndActivity("1", "1");
     // Default Filters for IM
     $this->view->item = 6;
     $this->view->date = Zend_Registry::get('report_month');
     // Default Filters for Campaign
     $this->view->camp = 23;
     $this->view->user_role = $role_id;
     $this->view->prov = $province;
     $r = $this->_request->getParam("ri_btn", '');
     if ($r == 'ri') {
         $this->view->r = $r;
         $this->view->item = $this->_request->getParam("items", '');
         $this->view->date = $this->_request->getParam("date", '');
         $this->view->period = $this->_request->getParam("period", '');
     }
     $i = $this->_request->getParam("im_btn", '');
     if ($i == 'im') {
         $this->view->i = $i;
         $this->view->item = $this->_request->getParam("items", '');
         $this->view->date = $this->_request->getParam("date", '');
         $this->view->period = $this->_request->getParam("period", '');
     }
     $c = $this->_request->getParam("camp_btn", '');
     if ($c == 'camp') {
         $this->view->c = $c;
         $this->view->camp = $this->_request->getParam("camp", '');
         $this->view->prov = $this->_request->getParam("prov", '');
     }
     $role_resource = new Model_RoleResources();
     $role_resource->form_values = array('type_id' => 3, 'role_id' => $role_id);
     $dashboards = $role_resource->getRoleResourcesByTypeForVlmisDashboard();
     $this->view->dashboards = $dashboards;
     $this->view->ri = 472;
     $this->view->im = 330;
     $this->view->campaign = 333;
     $period = new Model_Period();
     $time_intervals = $period->getTimeIntervals();
     $this->view->time_intervals = $time_intervals;
     $this->view->quarter = Model_Period::QUARTER;
     $this->view->halfyear = Model_Period::HALFYEAR;
     $this->view->annual = Model_Period::ANNUAL;
     $base_url = Zend_Registry::get('baseurl');
     $this->view->inlineScript()->appendFile($base_url . '/js/all_level_area_combo.js');
     $this->view->id = $this->_request->getParam("id", $dashboards[0]->getResource()->getPkId());
     /* if ($role_id == 7) {
        $this->view->province = $this->_identity->getProvinceId();
        $this->renderScript("dashboard/user-tehsil.phtml");
        } */
 }
 public function indexAction()
 {
     $auth = App_Auth::getInstance();
     $role_id = $auth->getRoleId();
     $campaign = new Model_Campaigns();
     $location = new Model_Locations();
     // National Level
     if ($role_id == 3 || $role_id == 23 || $role_id == 26 || $role_id == 27) {
         $this->view->level = 1;
     }
     // Provincial Level
     if ($role_id == 4 || $role_id == 23) {
         $this->view->level = 2;
         $province = $this->_identity->getProvinceId();
         $this->view->province = $province;
     }
     // 6 - District Level, 20 - Policy District User
     if ($role_id == 6 || $role_id == 7 || $role_id == 20 || $role_id == 21 || $role_id == 23) {
         $this->view->level = 6;
         $province = $this->_identity->getProvinceId();
         $district = $this->_identity->getDistrictId();
         $this->view->province = $province;
         $this->view->district = $district;
     }
     // National Campaign
     if ($role_id == 14 || $role_id == 23) {
         $province = 1;
         $this->view->province = $province;
         $district = 33;
         $this->view->district = $district;
     }
     // Provincial Campaign
     if ($role_id == 15 || $role_id == 23) {
         $province = $this->_identity->getUserLocationId();
         $this->view->province = $province;
     }
     // District Campaign
     if ($role_id == 16 || $role_id == 23) {
         $province = $this->_identity->getUserProvinceId();
         $district = $this->_identity->getUserLocationId();
         $this->view->province = $province;
         $this->view->district = $district;
     }
     if ($role_id == 17 || $role_id == 18 || $role_id == 23 || $role_id == 25 || $role_id == 26 || $role_id == 28 || $role_id == 29) {
         $province = 1;
         $district = 33;
         $this->view->province = $province;
         $this->view->district = $district;
         $this->view->level = 1;
     }
     if ($role_id == 27) {
         $province = 2;
         $district = 87;
         $this->view->province = $province;
         $this->view->district = $district;
         $this->view->level = 1;
     }
     if ($role_id == 30) {
         $province = $this->_identity->getProvinceId();
         $district = $this->_identity->getDistrictId();
         $this->view->province = $province;
         $this->view->district = $district;
         $this->view->level = 1;
     }
     if ($role_id == 31) {
         $province = 4;
         $district = 80;
         $this->view->province = $province;
         $this->view->district = $district;
         $this->view->level = 1;
     }
     $sel_lvl = $this->_request->getParam("office");
     if (!empty($sel_lvl)) {
         $level = $sel_lvl;
         $this->view->level = $level;
     }
     $sel_prov = $this->_request->getParam("combo1");
     if (!empty($sel_prov)) {
         $province = $sel_prov;
         $this->view->province = $province;
     }
     if ($role_id == 3 && empty($province)) {
         $province = 1;
         $this->view->province = $province;
     }
     $sel_dist = $this->_request->getParam("combo2");
     if (!empty($sel_dist)) {
         $district = $sel_dist;
         $this->view->district = $district;
     }
     if ($role_id == 3 && empty($district)) {
         $district = 33;
         $this->view->district = $district;
     }
     if ($role_id == 4 && empty($district)) {
         $location->form_values = array('geo_level_id' => 4, 'province_id' => $province);
         $res = $location->getLocationsByLevelByProvince();
         $district = $res[0]['key'];
         $this->view->district = $district;
     }
     switch ($level) {
         case 1:
             $this->view->campaigns = $campaign->getAllCampaigns();
             break;
         case 2:
             $location->form_values = array("province_id" => $province);
             $dists = $location->districtLocations();
             foreach ($dists as $dist) {
                 $arr_dist[] = $dist['pk_id'];
             }
             $campaign->form_values = array("districts" => implode(",", $arr_dist));
             $this->view->campaigns = $campaign->getCampaignsByDistrict();
             break;
         case 6:
             $campaign->form_values = array("districts" => $district);
             $this->view->campaigns = $campaign->getCampaignsByDistrict();
             break;
         default:
             $this->view->campaigns = $campaign->getAllCampaigns();
             break;
     }
     $this->view->provinces = $location->getProvincesName();
     $item = new Model_ItemPackSizes();
     $this->view->items = $item->getAllVaccines();
     // Default Filters for IM
     $this->view->item = 6;
     $this->view->date = Zend_Registry::get('report_month');
     // Default Filters for Campaign
     $this->view->camp = 23;
     $this->view->user_role = $role_id;
     $this->view->prov = $this->_identity->getProvinceId();
     $r = $this->_request->getParam("ri_btn", '');
     if ($r == 'ri') {
         $this->view->r = $r;
         $this->view->item = $this->_request->getParam("items", '');
         $this->view->date = $this->_request->getParam("date", '');
         $this->view->period = $this->_request->getParam("period", '');
     }
     $i = $this->_request->getParam("im_btn", '');
     if ($i == 'im') {
         $this->view->i = $i;
         $this->view->item = $this->_request->getParam("items", '');
         $this->view->date = $this->_request->getParam("date", '');
         $this->view->period = $this->_request->getParam("period", '');
     }
     $c = $this->_request->getParam("camp_btn", '');
     if ($c == 'camp') {
         $this->view->c = $c;
         $this->view->camp = $this->_request->getParam("camp", '');
         $this->view->prov = $this->_request->getParam("prov", '');
     }
     $role_resource = new Model_RoleResources();
     $role_resource->form_values = array('type_id' => 3, 'role_id' => $role_id);
     $dashboards = $role_resource->getRoleResourcesByType();
     $this->view->dashboards = $dashboards;
     $this->view->ri = 472;
     $this->view->im = 330;
     $this->view->campaign = 333;
     $period = new Model_Period();
     $time_intervals = $period->getTimeIntervals();
     $this->view->time_intervals = $time_intervals;
     $this->view->quarter = Model_Period::QUARTER;
     $this->view->halfyear = Model_Period::HALFYEAR;
     $this->view->annual = Model_Period::ANNUAL;
     $base_url = Zend_Registry::get('baseurl');
     $this->view->inlineScript()->appendFile($base_url . '/js/all_level_area_combo.js');
     if ($role_id == 4 || $role_id == 5 || $role_id == 6 || $role_id == 7) {
         $stock_master = new Model_StockMaster();
         $this->view->pending_receive = $stock_master->getPendingReceive();
         $this->view->warehouse_name = $auth->getWarehouseName();
     }
     $this->view->id = $this->_request->getParam("id", $dashboards[0]->getResource()->getPkId());
     /* if ($role_id == 7) {
        $this->view->province = $this->_identity->getProvinceId();
        $this->renderScript("dashboard/user-tehsil.phtml");
        } */
 }