Beispiel #1
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;
 }
 private function _crypt_me($str)
 {
     return fpp::cryptme($str);
 }
 public function password_recovery()
 {
     $id = 0;
     $passto = false;
     $errors = array();
     $msg = "";
     if ($this->ispost()) {
         $input = Input::Instance();
         $mail = $input->post('mail');
         if ($mail == '') {
             $errors[] = __("El Email no puede estar vacio", false);
         } else {
             if (valid::email($mail) == false) {
                 $errors[] = __("El Email no es valido", false);
             } else {
                 $orm = $this->table->db2cls();
                 $result = $orm->load($mail, 'mail_client');
                 $id = (int) $result->id_client;
                 if ($id == 0) {
                     $errors[] = __("El Email no existe", false);
                 } else {
                     $passto = true;
                     $passwordgenorig = basics::passwordgenerator();
                     $passwordgen = fpp::cryptme($passwordgenorig);
                     $result->password_client = $passwordgen;
                     $href = html::anchor($this->href_store);
                     basics::mail_html_utf8($mail, __('Recuperación de clave de acceso', false), __("Estimado Cliente, <br/>Su nueva contraseña es", false) . " {$passwordgenorig} <br/>{$href}", $this->mail_store, "Floreria Rosabel");
                     $passto = true;
                     $result->save();
                 }
             }
         }
         $msg = $passto == false ? basics::diverror($errors) : basics::diverror(array(__("E-mail enviado, revise su buz&oacute;n", false)));
     }
     $this->content = View::factory("main/recovery_password")->set("msg", $msg)->render();
 }