Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function add(){
- if(Session::get("tipo") == "admin"){
- Session::set('mod', isset($_POST['txtmod']) ? $_POST['txtmod'] : Session::get('mod'));
- $modelos = (Session::get('mod')!="") ? $this->mod_v->obtenerXDataList(Session::get('mod')) : array();
- if (isset($_POST['btnaceptar'])) {
- if($this->checkDates()) {
- if(isset($_FILES['foto'])){
- $ruta=$this->checkImage($_FILES['foto']);
- if($ruta!= null){
- $load= array($_POST['txtmat'],$_POST['txtcant'],$_POST['txtdes'],$ruta,$_POST['txtmod'],$_POST['cboxtipo']);
- $this->mod_v->guardame($load);
- Session::set('vehiculos', array());
- Session::set("msg","Vehículo Creado");
- $this->redirect(array('index.php'));
- exit();
- }
- }
- }
- }
- Session::set('modelos', $modelos);
- Session::set('tiposveh', $this->mod_tv->obtenerTodos());
- $this->redirect(array('add.php'));
- }
- else {
- Session::set("msg","Debe ser administrador para acceder.");
- $this->redirect(array('Main','index.php'));
- }
- }
- public function edit(){
- if(Session::get("tipo") == "admin"){
- Session::set("id",$_GET['p']);
- Session::set('mod', isset($_POST['txtmod']) ? $_POST['txtmod'] : Session::get('mod'));
- $modelos = (Session::get('mod')!="") ? $this->mod_v->obtenerXDataList(Session::get('mod')) : array();
- if (Session::get('id')!=null && isset($_POST['btnaceptar'])){
- if($this->checkDates()) {
- $load= array($_POST['hid'],$_POST['txtmat'],$_POST['txtcant'],$_POST['txtdes'],$_POST['txtmod'],$_POST['cboxtipo']);
- $this->mod_v->modificame($load);
- Session::set('vehiculos', array());
- Session::set("msg","Vehículo Editado");
- $this->redirect(array('index.php'));
- exit();
- }
- }
- Session::set('vehiculo', $this->mod_v->obtenerXId(Session::get('id')));
- Session::set('modelos', $modelos);
- Session::set('tiposveh', $this->mod_tv->obtenerTodos());
- $this->redirect(array('edit.php'));
- }
- else {
- Session::set("msg","Debe ser administrador para acceder.");
- $this->redirect(array('Main','index.php'));
- }
- }
- public function foto(){
- if(Session::get("tipo") == "admin"){
- if (isset($_POST['btnaceptar'])) {
- if(isset($_FILES['foto'])){
- $ruta= $this->checkImage($_FILES['foto']);
- if($ruta!= null){
- $load=array(Session::get('vehiculo')['vehId'],$ruta);
- $this->mod_v->mod_foto($load);
- echo 'anda';
- header("Location:index.php?c=vehiculos&a=edit&p=$load[0]");
- exit();
- }
- }
- }
- $this->redirect(array('foto.php'));
- }
- else {
- Session::set("msg","Debe ser administrador para acceder.");
- $this->redirect(array('Main','index.php'));
- }
- }
- private function checkImage($file){
- if ($file["error"] > 0){
- Session::set('msg', "ha ocurrido un error");
- return null;
- }
- else {
- $permitidos = array("image/jpg", "image/jpeg", "image/gif", "image/png");
- if($this->checkExtension($file)){
- $prefijo = substr(md5(uniqid(rand())),0,6);
- $ruta = "View/Layout/upload/".$prefijo."_".$file['name'];
- $limite_kb = 100;
- if (in_array($file['type'], $permitidos) && $file['size'] <= $limite_kb * 1024){
- $resultado = move_uploaded_file($file["tmp_name"], $ruta);
- return ($resultado) ? $ruta : null;
- }
- else {
- Session::set('msg', "tipo de archivo no permitido o excede a los $limite_kb kb");
- return null;
- }
- }
- else {
- Session::set('msg', "error en la extensión");
- return null;
- }
- }
- }
- private function checkExtension($file){
- $file['type'] = pathinfo($file['name'], PATHINFO_EXTENSION);
- $types = array('jpg', 'jpeg','png', 'gif');
- foreach($types as $type){
- if($type == $file['type']){
- return true;
- }
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement