public function __toString()
 {
     /**
      * poa = product options atributes
      */
     //     echo Kohana::debug(@$_POST);
     $opa = new fpp_product_has_attributes_product_Model();
     $orm = $opa->db2cls();
     $uri = URI::Instance();
     $id = (int) $uri->segment("edit");
     if (request::method() == 'post' and is_array(@$_POST['opt'])) {
         $orm->delete(array('product_id_product' => $id));
         foreach ($_POST['opt'] as $key => $value) {
             $orm = $opa->db2cls();
             $data['product_id_product'] = $id;
             //         $data['ap_id_attributes_product']            = @$_POST['atr'][$key];
             $data['prefix'] = @$_POST['prefix'][$key];
             $data['vap_id_values_atributtes_product'] = @$_POST['opt'][$key];
             $data['value'] = @$_POST['val'][$key];
             $data['extra'] = @$_POST['extra'][$key];
             $orm->set_fields($data);
             $orm->save();
         }
     }
     $results = $this->GetAttr($id);
     //     fetch_where(array('product_id_product'=> ) );
     $atr_p = new fpp_attributes_product_Model();
     $orm_atrp = $atr_p->db2cls();
     $attributes = form::dropdown("poa_id", $orm_atrp->select_list('id_attributes_product', 'name_attributes_product'));
     $string = View::factory("extras/ajaxattributes")->set("attributes", $attributes)->set("results", $results)->render();
     return $string;
 }
示例#2
0
 function detailnews($id)
 {
     $uri = URI::Instance();
     //     $id = (int) $uri->segment("detailnews");
     //     $this->_NoTemplate();
     $orm = new fpp_news_Model();
     $orm = $orm->db2cls($id);
     $title_news = Basic::TransVar("title_news");
     $content_news = Basic::TransVar("content_news");
     $this->title = $orm->{$title_news};
     $this->content = View::factory("main/page")->set("title", __("Eventos", false))->set("content", "<h4>" . $orm->{$title_news} . "</h4>" . $orm->{$content_news})->render();
     //     $this->content = View::factory("webservices/news_detail")
     //       ->set("news",$orm)
     //       ->render();
 }
示例#3
0
 public function blockfields($id = null)
 {
     $idorigin = $id;
     if ($id != null) {
         settype($id, 'integer');
     }
     if ($id === 0 and $idorigin != 'LOOK') {
         return NULL;
     }
     $msg = null;
     $types = new fpp_fieldtype_Model($this->meta);
     $types->SetPkID($id);
     $types->AddAttributes('NameModel', get_class($this));
     $types->AddAttributes('Primary', $this->_FirstPrimary);
     $fields =& $types->fields;
     $this->_apply_php($types);
     $arrayWhere = null;
     $select = null;
     $arrayTables[] = $this->_Table;
     $first = null;
     $items = $this->show;
     $OneToMany = array();
     //construccion de qu campos se van a mostrar
     if ($items == "AUTO") {
         $items = array();
         foreach ($this->meta as $fieldname => $props) {
             $items[] = $fieldname;
         }
     }
     //cargando las propiedades de cada campo
     $OTMSelect = array();
     foreach ($items as $fieldname) {
         if ($first == null) {
             $first = $fieldname;
         }
         $object = $fields->{$fieldname};
         $db_field = "{$this->_Table}.{$fieldname}";
         if ($object->typefield != 'OneToMany') {
             $select[] = $db_field;
         } else {
             $OTMSelect[] = $fieldname;
         }
         $titles[$fieldname] = $this->_File_i18n == null ? $object->verbose : Kohana::lang($this->_File_i18n . '.' . $object->verbose);
         $choice[$fieldname] = $object->choices;
     }
     if ($this->_AddField != null) {
         foreach ($this->_AddField as $data) {
             $table = $data['table'];
             $db_field = "{$table}.{$data['field']}";
             $select[] = $db_field;
             $arrayTables[$table] = $table;
         }
     }
     //si es post , grabara los cambios
     if (request::method() == 'post' and $this->_OnlyRead == FALSE) {
         $save = $this->save;
         if ($save == 'AUTO') {
             $save = array();
             foreach ($this->meta as $fieldname => $props) {
                 $save[] = $fieldname;
             }
         }
         $input = Input::instance();
         foreach ($save as $field) {
             $foreach_typefield =& $types->fields->{$field}->typefield;
             if ($types->fields->{$field}->typefield == 'CheckField' and @$_POST[$field] == '') {
                 $_POST[$field] = FALSE;
             }
             if ($foreach_typefield == 'PasswordField') {
                 $_POST[$field] = fpp::cryptme($_POST[$field]);
             }
             if ($input->post($field) !== null and $types->fields->{$field}->typefield != 'OneToMany' and $types->fields->{$field}->typefield != 'TabularModel') {
                 $inp = $input->post($field);
                 $tmp_inp = $inp;
                 if ($types->fields->{$field}->post_exec != null and request::method() == 'post') {
                     $value = $input->post($field);
                     eval($types->fields->{$field}->post_exec . ';');
                     $inp = $value;
                 }
                 $update_fields[$field] = $inp;
             }
             //Preparando los Uno a muchos, y muchos a muchos
             if ($types->fields->{$field}->typefield == 'OneToMany' or $types->fields->{$field}->typefield == 'TabularModel') {
                 $modtable = substr($types->fields->{$field}->model, 4);
                 $metaOTM = fpp::GetOTM($modtable, $this->_Table);
                 $metaOTM['fieldhtml'] = $input->post($field);
                 $metaOTM['pk'] = $field;
                 $OneToMany[$field] = $metaOTM;
                 $this->db->delete($modtable, array($metaOTM['primary'] => $id));
             }
         }
         /**/
         if ($this->_AddKeyField != null) {
             foreach ($this->_AddKeyField as $field => $FValue) {
                 $update_fields[$field] = $FValue;
             }
         }
         if (isset($_FILES)) {
             foreach ($_FILES as $key => $value) {
                 // Checking Files (Upload Only Images)
                 $this->file_type = $_FILES[$key]['type'];
                 if (!($this->file_type != 'image/jpg' && $this->file_type != 'image/x-png' && $this->file_type != 'image/pjpeg' && $this->file_type != 'image/jpeg' && $this->file_type != 'image/gif' && $this->file_type != 'video/avi' && $this->file_type != 'video/msvideo' && $this->file_type != 'video/x-msvideo' && $this->file_type != 'image/png')) {
                     //Execute IF statment
                     try {
                         $retupload = upload::save($_FILES[$key]);
                     } catch (Exception $e) {
                         echo Kohana::debug('Error: ' . "\n" . $e->getMessage() . "\n");
                         die;
                     }
                     $retupload = explode('upload/', $retupload);
                     if (count($retupload) > 1) {
                         $retupload = $retupload[1];
                         $update_fields[$key] = $retupload;
                         $value = $retupload;
                         if ($types->fields->{$key}->post_exec != null and request::method() == 'post') {
                             eval($types->fields->{$key}->post_exec . ';');
                         }
                     }
                 }
             }
         }
         if ($id != null) {
             try {
                 $status = $this->db->update($this->_Table, $update_fields, array($first => $id));
             } catch (Exception $e) {
                 echo Kohana::debug('Error: ' . "\n" . $e->getMessage() . "\n");
                 die;
             }
         } else {
             try {
                 $status = $this->db->insert($this->_Table, $update_fields);
                 $id = $status->insert_id();
             } catch (Exception $e) {
                 echo Kohana::debug('Error: ' . "\n" . $e->getMessage() . "\n");
                 die;
             }
         }
         if (@$_SESSION['PKID'] != "" and @$_GET['AJAX_NO_LOAD'] == TRUE) {
             $_SESSION['PKID_OTM'] = $id;
         }
         if (is_array($OneToMany)) {
             foreach ($OneToMany as $valueOTM) {
                 if (is_array($valueOTM['fieldhtml'])) {
                     foreach ($valueOTM['fieldhtml'] as $value) {
                         $arrOTMnew = array($valueOTM['primary'] => $id, $valueOTM['secondary'] => $value);
                         $this->db->insert($valueOTM['table'], $arrOTMnew);
                     }
                 }
             }
         }
         $this->_Response = TRUE;
         $msg = fpp::fppmsg('Guardo Correctamente');
     }
     if ($id != null or $idorigin == 'LOOK') {
         //Inicializacion del query (construccion & carga)
         $strinTables = implode(',', $arrayTables);
         $select = implode(',', $select);
         $query = $this->db->select($select)->from($strinTables)->limit(1, 0);
         if (is_array($arrayWhere)) {
             $stringWhere = implode(' AND ', $arrayWhere);
             $query = $query->where($stringWhere);
         }
         if ($idorigin != 'LOOK') {
             $wherearray[] = "{$first} = {$id}";
         }
         if ($this->_AddKeyField != null) {
             foreach ($this->_AddKeyField as $Fkey => $FValue) {
                 $wherearray[] = "{$Fkey} = {$FValue}";
             }
         }
         if ($this->_FilterActive != null) {
             foreach ($this->_FilterActiveByInfo as $filter => $value) {
                 $wherearray[] = "{$this->_Table}.{$filter} = {$value}";
             }
         }
         $where_string = implode(' AND ', $wherearray);
         $query = $query->where($where_string);
         try {
             $rows = $query->get();
         } catch (Exception $e) {
             echo Kohana::debug('Error: ' . "\n" . $e->getMessage() . "\n");
             die;
         }
         //escribiendo los campos de acuerdo a sus propiedades
         $data = new StdClass();
         $types->base_uri = $this->base_uri;
         $valid_count = FALSE;
         foreach ($rows as $row) {
             foreach ($OTMSelect as $nameOTM) {
                 $row->{$nameOTM} = 'null';
             }
             foreach ($row as $name => $value) {
                 $valid_count = TRUE;
                 if ($this->_OnlyRead == TRUE) {
                     $data->{$name} = $value;
                 } else {
                     $types->field_value = $value;
                     //          Si el campo es un "OneToMany"
                     if ($types->fields->{$name}->typefield == 'OneToMany' or $types->fields->{$name}->typefield == 'TabularModel') {
                         if (@$OneToMany[$name]['table'] == '') {
                             $modtable = substr($types->fields->{$name}->model, 4);
                             $OneToMany[$name] = fpp::GetOTM($modtable, $this->_Table);
                         }
                         $OTMArr = null;
                         //              Tomo el campo primario y secundario
                         $OTMdb_field = $OneToMany[$name]['secondary'];
                         $OTMdb_pk = $OneToMany[$name]['primary'];
                         $valuelistOTM = null;
                         try {
                             $valuelistOTM = $this->db->from($OneToMany[$name]['table'])->select($OTMdb_field)->where(array($OTMdb_pk => $id))->get();
                         } catch (Exception $e) {
                             echo Kohana::debug('Error: ' . "\n" . $e->getMessage() . "\n");
                             die;
                         }
                         foreach ($valuelistOTM as $rowOTM) {
                             $OTMArr[] = $rowOTM->{$OTMdb_field};
                         }
                         $types->field_value = $OTMArr;
                     }
                     $types->field_name = $name;
                     $arrayorder[$name] = $types->ObjectField($name);
                 }
             }
             foreach ($this->meta as $fieldname => $props) {
                 $data->{$fieldname} = $arrayorder[$fieldname];
             }
         }
     } else {
         foreach ($items as $name) {
             $valid_count = TRUE;
             $types->field_name = $name;
             $types->field_value = NULL;
             $data->{$name} = $types->ObjectField($name);
         }
     }
     //VIRTUAL
     if ($this->virtual != null) {
         $dirf = dirname(__FILE__);
         include_once $dirf . '/types/' . $this->virtual . '.php';
         $data->virtualfield = new $this->virtual();
         $data->virtualfield->id_table = $id;
         $titles['virtualfield'] = $data->virtualfield->title;
     }
     if ($this->virtualclone != null) {
         $dirf = dirname(__FILE__);
         include_once $dirf . '/types/' . $this->virtualclone . '.php';
         $data->virtualfieldc = new $this->virtualclone();
         $data->virtualfieldc->id_table = $id;
         $titles['virtualfieldc'] = $data->virtualfieldc->title;
     }
     //VIRTUAL
     if ($valid_count == FALSE) {
         return NULL;
     }
     $this->retfields = $data;
     //Setting Ajax
     $form = null;
     $attrform = null;
     if (@$_GET['AJAX_NO_LOAD'] == TRUE) {
         $form .= '<script>$(document).ready(function(){$(".FORM_AJAX").submit(function(){ return post_ajax(this); })});</script>';
         $attrform = array("class" => 'FORM_AJAX');
     }
     $urlform = NULL;
     if ($id > 0) {
         $this->uri = URI::Instance();
         $urlform = str_replace("add", "edit/" . $id, $this->uri);
     }
     $form .= form::open_multipart($urlform, $attrform);
     if ($this->GetFieldAjax != NULL) {
         $FAjax = $this->GetFieldAjax;
         return $data->{$FAjax};
     }
     $view_info = $this->_TabView == TRUE ? 'tabmodel' : 'info';
     $str = View::factory($this->templatedir . $view_info)->set('msg', $msg)->set('data', $data)->set('form', $form)->set('only_read', $this->_OnlyRead)->set('titles', $titles)->set('tblname', $this->_Table)->render();
     return $str;
 }