/**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the ID of the model to be loaded
  * @return SolutionsOptions the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = SolutionsOptions::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
 public function actionAdminSolns()
 {
     if (isset($_GET['id'])) {
         $id = intval($_GET['id']);
         $curUser = Customer::model()->findByPk($id);
         if (empty($curUser->id)) {
             throw new CHttpException(403, 'Customer Does\'t exists');
         }
         Yii::app()->session['last_created_user'] = $curUser->attributes;
     }
     if (getParam('ajax') == 1) {
         $mspoon = MagicSpoolAns::model()->findByAttributes(array('cus_id' => getCurCusId()));
         if (!$mspoon) {
             $mspoon = new MagicSpoolAns();
             $mspoon->cus_id = getCurCusId();
         }
         $mspoon->one = isset($_POST['one']) ? $_POST['one'] : "";
         $mspoon->two = isset($_POST['two']) ? $_POST['two'] : "";
         $mspoon->three = isset($_POST['three']) ? $_POST['three'] : "";
         $mspoon->four = isset($_POST['four']) ? $_POST['four'] : "";
         $mspoon->five = isset($_POST['five']) ? $_POST['five'] : "";
         $mspoon->one_comment = isset($_POST['magicspools']['one']['comment']) ? $_POST['magicspools']['one']['comment'] : "";
         $mspoon->two_comment = isset($_POST['magicspools']['two']['comment']) ? $_POST['magicspools']['two']['comment'] : "";
         $mspoon->three_comment = isset($_POST['magicspools']['three']['comment']) ? $_POST['magicspools']['three']['comment'] : "";
         $mspoon->four_comment = isset($_POST['magicspools']['four']['comment']) ? $_POST['magicspools']['four']['comment'] : "";
         $mspoon->five_comment = isset($_POST['magicspools']['five']['comment']) ? $_POST['magicspools']['five']['comment'] : "";
         $mspoon->one_like = isset($_POST['magicspools']['one']['like']) ? intval($_POST['magicspools']['one']['like']) : "0";
         $mspoon->two_like = isset($_POST['magicspools']['two']['like']) ? intval($_POST['magicspools']['two']['like']) : "0";
         $mspoon->three_like = isset($_POST['magicspools']['three']['like']) ? intval($_POST['magicspools']['three']['like']) : "0";
         $mspoon->four_like = isset($_POST['magicspools']['four']['like']) ? intval($_POST['magicspools']['four']['like']) : "0";
         $mspoon->five_like = isset($_POST['magicspools']['five']['like']) ? intval($_POST['magicspools']['five']['like']) : "0";
         $mspoon->save();
         $option = Options::model()->findAll(array('limit' => 1));
         if (getParam('selp')) {
             foreach (getParam('selp') as $prod) {
                 $selp = SelProducts::model()->findByPk($prod['selproid']);
                 if (!$selp) {
                     continue;
                 }
                 $selp->attributes = $prod;
                 $selp->menu_name = $prod['menuname'];
                 $selp->price_per_head_f = $prod['price_per_head_pound'];
                 $selp->save();
             }
         }
         if (getParam('selcat')) {
             foreach (getParam('selcat') as $prod) {
                 $selCat = SelectedCategories::model()->findByPk($prod['selproid']);
                 $selCat->attributes = $prod;
                 $selCat->menuname = $prod['menuname'];
                 $selCat->price = $prod['price_per_head_pound'];
                 $selCat->notes = $prod['notes'];
                 //                    mA($selCat);
                 $selCat->save();
             }
         }
         $url;
         if (yii::app()->user->isUser()) {
             if ($option[0]->id > 3) {
                 $url = createUrl('options/optionView', array('id' => $option[0]->id));
             } else {
                 $url = createUrl('options/optionView', array('id' => $option[0]->id));
             }
         } elseif (yii::app()->user->isFranchiseAdmin()) {
             if ($option[0]->id > 3) {
                 $url = createUrl('options/optionsView', array('options_num' => $option[0]->id, 'custom' => 1));
             } else {
                 $url = createUrl('options/optionsView', array('options_num' => $option[0]->id));
             }
         } else {
             $url = createUrl('customer/list');
         }
         $this->redirect($url);
     }
     //        $cust = Customer::model()->findAll(array(
     //            'condition' => 'id=:id ',
     //            'params' => array(':id' => getCurCusId()),
     //        ));
     $cust = Customer::model()->findByPk(getCurCusId());
     $temp = array();
     $selCategory = SelectedCategories::model()->findAll(array("condition" => "user_id =" . getCurCusId()));
     $selProd = $sel_prods = array();
     $sel_cat_prods = array();
     $pordIndex = 0;
     foreach ($selCategory as $sel) {
         $prodArr = CJSON::decode($sel->product_ids);
         foreach ($prodArr as $prodId) {
             $pordIndex++;
             $sel_prods[] = $prodId;
         }
         $sel_cat_prods[$sel->cat_id] = $prodArr;
     }
     /*
              * Old logic and Inder has done this code.
              * $selCategory = SelectedCategories::model()->findAll(array(
                 'condition' => "user_id=" . getCurCusId() . " and cat_id not in (" . getAllowedCategoriesId() . ")"
             ));
                     
     		//e($selCategory);
             //e($categories);
             $selProd = SelProducts::model()->findAll(array(
                 "condition" => "cus_id =" . getCurCusId(),
                 "order" => 'product_id asc'
             ));
             foreach ($selProd as $sel):
                 if (!in_array($sel->product->category->id, array(1092507473, 1092507462, 1092507463)))
                     continue;
                 $temp[$sel->product->category->order][] = $sel;
             endforeach;
             ksort($temp);
             $selProd = array();
             foreach ($temp as $t):
                 foreach ($t as $tt):
                     $selProd[] = $tt;
                 endforeach;
             endforeach;
     		
     //        e($selProd[0]->product->category);
     * 		$selData = CHtml::listData($selProd, 'id', 'product_id');
     * */
     $criteria = new CDbCriteria();
     $criteria->order = 'id asc';
     $criteria->addInCondition('id', $sel_prods);
     $selproducts = Product::model()->findAll($criteria);
     $temp = array();
     foreach ($selproducts as $prodDet) {
         $temp[$prodDet->id] = $prodDet;
     }
     $selproducts = $temp;
     $magicSpools = $cust->magicSpools;
     $magicSpoolsAns = $cust->magicSpoolsAns;
     if (isset($_POST['ajax']) && $_POST['ajax'] == 1) {
         $cust[0]->unable_to_commit = $_POST['final_comment'];
         $cust[0]->save();
     }
     //e($selproducts);
     //$selCategory = $temp;
     $solution_model = new SolutionsOptions();
     $solutions_opt = CHtml::listData($solution_model->findAll('enable=1'), 'description', 'description');
     $this->render('adminsolns', array('solutions_opt' => $solutions_opt, 'customer' => $cust, 'magic_spools' => $magicSpools, 'magicSpoolsAns' => $magicSpoolsAns, 'selCategory' => $selCategory, 'selProd' => $selProd, 'selproducts' => $selproducts, 'sel_cat_prods' => $sel_cat_prods));
 }