Ejemplo n.º 1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Sales();
     $users = User::getNames();
     foreach (Groups::model()->findAll() as $group) {
         $users[$group->id] = $group->name;
     }
     unset($users['admin']);
     unset($users['']);
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Sales'])) {
         $temp = $model->attributes;
         $model->setX2Fields($_POST['Sales']);
         // die(var_dump($model));
         /* foreach($_POST['Sales'] as $name => &$value) {
         				if($value == $model->getAttributeLabel($name))
         					$value = '';
         			}
         			foreach($_POST as $key=>$arr){
         				$pieces=explode("_",$key);
         				if(isset($pieces[0]) && $pieces[0]=='autoselect'){
         					$newKey=$pieces[1];
         					if(isset($_POST[$newKey."_id"]) && $_POST[$newKey."_id"]!=""){
         						$val=$_POST[$newKey."_id"];
         					}else{
         						$field=Fields::model()->findByAttributes(array('fieldName'=>$newKey));
         						if(isset($field)){
         							$type=ucfirst($field->linkType);
         							if($type!="Contacts"){
         								eval("\$lookupModel=$type::model()->findByAttributes(array('name'=>'$arr'));");
         							}else{
         								$names=explode(" ",$arr);
         								$lookupModel=Contacts::model()->findByAttributes(array('firstName'=>$names[0],'lastName'=>$names[1]));
         							}
         							if(isset($lookupModel))
         								$val=$lookupModel->id;
         							else
         								$val=$arr;
         						}
         					}
         					$model->$newKey=$val;
         				}
         			}
         			foreach(array_keys($model->attributes) as $field){
         				if(isset($_POST['Sales'][$field])){
         					$model->$field=$_POST['Sales'][$field];
         					$fieldData=Fields::model()->findByAttributes(array('modelName'=>'Sales','fieldName'=>$field));
         						if($fieldData->type=='assignment' && $fieldData->linkType=='multiple'){
         							$model->$field=Accounts::parseUsers($model->$field);
         						}elseif($fieldData->type=='date'){
         							$model->$field=strtotime($model->$field);
         						}
         				}
         			} */
         $this->create($model, $temp);
     }
     $this->render('create', array('model' => $model, 'users' => $users));
 }