Esempio n. 1
0
 public function addAction()
 {
     $form = new TestForm($this->getServiceLocator()->get('Admin\\Model\\TestTable'));
     //$form = new ActivityForm();
     $form->get('submit')->setValue('Add');
     $request = $this->getRequest();
     if ($request->isPost()) {
         $test = new Test();
         $form->setInputFilter($test->getInputFilter());
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $formData = array();
             $formData = $form->getData();
             $renameUpload = new \Zend\Filter\File\RenameUpload(array('target' => "./public/uploads/", 'randomize' => true, 'use_upload_name' => true));
             if ($fileDetails = $renameUpload->filter($_FILES['document'])) {
                 $formData['document'] = $fileDetails['tmp_name'];
                 $test->exchangeArray($formData);
             }
             $test->exchangeArray($formData);
             $this->getTestTable()->saveTest($test);
             $this->flashMessenger()->addSuccessMessage('Test added successfully..!!');
             // Redirect to list of pages
             return $this->redirect()->toRoute('admin/test');
         } else {
             $this->errors = $form->getMessages();
         }
     }
     return array('form' => $form, 'errors' => $this->errors);
 }
 /**
  * Carga el formulario para ingresar el nuevo proyecto vial , cuando la peticion es post guarda la los datos del proyecto
  * 
  * @return \Zend\View\Model\ViewModel
  */
 public function crearAction()
 {
     if ($this->getRequest()->isPost()) {
         $this->layout('layout/layoutV1');
         $datos = $this->getRequest()->getPost();
         $files = $this->getRequest()->getFiles()->toArray();
         $projectV = new proyectoV();
         $project = new proyecto();
         $estado = $this->em()->getRepository('\\Login\\Model\\Entity\\Estado')->find($datos["estado"]);
         $eje = $this->em()->getRepository('\\Login\\Model\\Entity\\Eje')->find(3);
         $tipoObra = $this->em()->getRepository('\\Login\\Model\\Entity\\TipoObra')->find($datos["tipoObra"]);
         $barrio = $this->em()->getRepository('\\Login\\Model\\Entity\\Barrio')->find($datos["barrio"]);
         $ejecutor = $this->em()->getRepository('\\Login\\Model\\Entity\\Ejecutor')->find($datos["ejecutor"]);
         $project->setEstado($estado);
         $project->setEje($eje);
         $project->setProyectoPathfotos('pendiente');
         $project->setProyectoAnio($datos["anio"]);
         $project->setProyectoPresupuesto($datos["presupuesto"]);
         $projectV->setProyecto($project);
         $projectV->setProyectoviasTramo($datos["tramo"]);
         $projectV->setProyectoviasDirinicio($datos["dirInicio"]);
         $projectV->setProyectoviasDirfinal($datos["dirFinal"]);
         $projectV->setProyectoviasCiv($datos["civ"]);
         $projectV->setTipoobra($tipoObra);
         $projectV->setBarrio($barrio);
         $projectV->setProyectoviasLargo($datos["largo"]);
         $projectV->setProyectoviasAncho($datos["ancho"]);
         $projectV->setProyectoviasInterventor($datos["interventor"]);
         $projectV->setProyectoviasEjecutor($ejecutor);
         $projectV->setProyectoviasCoordenadas($datos["coordenadas"]);
         $this->dbh()->insertObj($projectV);
         $ruta = './public/fotografias/' . $project->getProyectoId() . '/';
         if (!file_exists($ruta)) {
             mkdir($ruta);
         }
         $filter = new \Zend\Filter\File\RenameUpload($ruta);
         $filter->setUseUploadName(true);
         foreach ($files['proyecto-fotos'] as $file) {
             $filter->filter($file);
         }
         return $this->forward()->dispatch('Vias\\Controller\\index', array('action' => 'cargar', 'via' => $projectV));
     } else {
         $this->layout('layout/layoutV1');
         $this->layout()->titulo = '.::Crear Proyecto Vial::.';
         $formCrearProyVia = new FormGuardarVia($this->em());
         return new ViewModel(array("formCrearProyVia" => $formCrearProyVia, "url" => $this->getRequest()->getBaseUrl()));
     }
 }
Esempio n. 3
0
 public function indexAction()
 {
     $this->layout("layout/admin");
     $request = $this->getRequest();
     if ($request->isPost()) {
         $file = $request->getFiles()->toArray();
         $filter = new \Zend\Filter\File\RenameUpload(['target' => APP_DIR . '/../public/uploads/img.png', 'randomize' => true]);
         $name = $filter->filter($file["file"]);
         $post['name'] = $file["file"]["name"];
         $temp = explode('/', $name["tmp_name"]);
         $post['url'] = "uploads/" . $temp[count($temp) - 1];
         $m = new Media();
         $m->exchangeArray($post);
         $this->getMediaTable()->add($m);
     }
     return ['message' => isset($message) ? $message : null, 'form' => new MediaForm(), 'images' => $this->getMediaTable()->select(null, null, null, null, null, "ID desc")];
 }
 public function updateAction()
 {
     $request = $this->getRequest();
     if ($request->isPost()) {
         $action = $request->getPost('action');
         $api = new Api();
         $common = new Common();
         $model = new Practitioners();
         $bookingModel = new Bookings();
         $session = new Container('frontend');
         $user_id = $session->userid;
         $api_url = $this->getServiceLocator()->get('config')['api_url']['value'];
         switch ($action) {
             case 'name':
                 $contact_data['user_id'] = $user_id;
                 $contact_data = $user_data = $errors = array();
                 $contact_id = $request->getPost('contact_id');
                 $full_name = explode(' ', trim($request->getPost('practitioner_name')));
                 isset($full_name[0]) && $full_name[0] != '' ? $contact_data['first_name'] = $user_data['first_name'] = ucfirst($full_name[0]) : '';
                 isset($full_name[1]) && $full_name[1] != '' ? $contact_data['last_name'] = $user_data['last_name'] = ucfirst($full_name[1]) : ($contact_data['last_name'] = $user_data['last_name'] = '');
                 $result = $model->updateContact($api_url, $contact_data, $contact_id);
                 if ($result == true) {
                     $result = $model->updateData($api_url, $user_data, $user_id);
                     if ($result == true) {
                         echo json_encode(array('status' => 1, 'msg' => 'Name successfully updated..!!'));
                     } else {
                         if (is_array($result)) {
                             echo json_encode(array('status' => 0, 'errors' => $result));
                         } else {
                             echo json_encode(array('status' => 0, 'msg' => 'Failed to update name..!!'));
                         }
                     }
                 } else {
                     if (is_array($result)) {
                         echo json_encode(array('status' => 0, 'errors' => $result));
                     } else {
                         echo json_encode(array('status' => 0, 'msg' => 'Failed to update name..!!'));
                     }
                 }
                 break;
             case 'profile':
                 $details_data = $address_data = array();
                 $address_data['user_id'] = $details_data['user_id'] = $user_id;
                 $address_data['user_type'] = '';
                 $detail_id = $request->getQuery('detail_id');
                 $address_id = $request->getQuery('address_id');
                 trim($request->getQuery('designation')) != "" ? $details_data['designation'] = trim($request->getQuery('designation')) : '';
                 trim($request->getQuery('company_name')) != "" ? $details_data['company_name'] = trim($request->getQuery('company_name')) : '';
                 trim($request->getQuery('dob')) != "" ? $details_data['dob'] = date('Y-m-d', strtotime(trim($request->getQuery('dob')))) : '';
                 trim($request->getQuery('specialties')) != "" ? $details_data['specialties'] = trim($request->getQuery('specialties')) : '';
                 trim($request->getQuery('degrees')) != "" ? $details_data['degrees'] = trim($request->getQuery('degrees')) : '';
                 trim($request->getQuery('years_of_experience')) != "" ? $details_data['years_of_experience'] = str_replace(' Years', '', trim($request->getQuery('years_of_experience'))) : '';
                 trim($request->getQuery('prof_membership')) != "" ? $details_data['prof_membership'] = trim($request->getQuery('prof_membership')) : '';
                 trim($request->getQuery('professional_license_number')) != "" ? $details_data['professional_license_number'] = trim($request->getQuery('professional_license_number')) : '';
                 trim($request->getQuery('awards_and_publication')) != "" ? $details_data['awards_and_publication'] = trim($request->getQuery('awards_and_publication')) : '';
                 trim($request->getQuery('auth_to_bill_insurence_copany')) != "" ? $details_data['auth_to_bill_insurence_copany'] = trim($request->getQuery('auth_to_bill_insurence_copany')) : '';
                 trim($request->getQuery('auth_to_issue_insurence_rem_receipt')) != "" ? $details_data['auth_to_issue_insurence_rem_receipt'] = trim($request->getQuery('auth_to_issue_insurence_rem_receipt')) : '';
                 trim($request->getQuery('treatment_for_physically_disabled_person')) != "" ? $details_data['treatment_for_physically_disabled_person'] = trim($request->getQuery('treatment_for_physically_disabled_person')) : '';
                 trim($request->getQuery('offering_at_home')) != "" ? $details_data['offering_at_home'] = trim($request->getQuery('offering_at_home')) : '';
                 trim($request->getQuery('offering_at_work_office')) != "" ? $details_data['offering_at_work_office'] = trim($request->getQuery('offering_at_work_office')) : '';
                 trim($request->getQuery('age')) != "" ? $user_data['age'] = trim($request->getQuery('age')) : '';
                 trim($request->getQuery('gender')) != "" ? $user_data['gender'] = trim($request->getQuery('gender')) : '';
                 // Updating languges
                 if ($model->updateLanguages($api_url, $user_id, $request->getQuery('language'))) {
                     // Updating educations
                     if ($model->updateEducations($api_url, $user_id, $request->getQuery('education'))) {
                         // Updating practitioner details
                         $result = $model->updateDetails($api_url, $details_data, $detail_id);
                         if ($result['status'] == 1) {
                             // Updating practitioner address
                             $res = $model->updateData($api_url, $user_data, $user_id);
                             if ($res == true) {
                                 echo json_encode(array('status' => 1, 'msg' => 'Profile updated successfully..!!', 'data' => array('detail_id' => $result['id'], 'address_id' => $response['id'])));
                             } else {
                                 if (is_array($res)) {
                                     echo json_encode(array('status' => 0, 'errors' => $res));
                                 } else {
                                     echo json_encode(array('status' => 0, 'msg' => 'Failed to update profile..!!'));
                                 }
                             }
                         } else {
                             echo json_encode($result);
                         }
                     } else {
                         echo json_encode(array('status' => 0, 'msg' => 'Failed to update languages..!!'));
                     }
                 } else {
                     echo json_encode(array('status' => 0, 'msg' => 'Failed to update languages..!!'));
                 }
                 break;
             case 'about':
                 $details_data = array();
                 $details_data['user_id'] = $user_id;
                 $detail_id = $request->getQuery('detail_id');
                 trim($request->getQuery('description')) != "" ? $details_data['description'] = addslashes(trim(str_replace(array("\r", "\n"), '', nl2br($request->getQuery('description'))))) : '';
                 echo json_encode($model->updateDetails($api_url, $details_data, $detail_id));
                 break;
             case 'contact':
                 $contact_data = array();
                 $contact_data['user_id'] = $user_id;
                 $contact_id = $request->getQuery('contact_id');
                 trim($request->getQuery('cellphone')) != "" ? $contact_data['cellphone'] = trim($request->getQuery('cellphone')) : '';
                 trim($request->getQuery('phone_number')) != "" ? $contact_data['phone_number'] = trim($request->getQuery('phone_number')) : '';
                 if (isset($contact_data['cellphone']) && $contact_data['cellphone'] != '' && !preg_match('/^\\d{11}$/', $contact_data['cellphone'])) {
                     echo json_encode(array('status' => 0, 'msg' => 'Main phone number should be 11 digit number (1 as a prefix and 10 digit phone number)..!!'));
                 } elseif (isset($contact_data['phone_number']) && $contact_data['phone_number'] != '' && !preg_match('/^\\d{11}$/', $contact_data['phone_number'])) {
                     echo json_encode(array('status' => 0, 'msg' => 'Office phone number should be 11 digit number (1 as a prefix and 10 digit phone number)..!!'));
                 } else {
                     echo json_encode($model->updateContact($api_url, $contact_data, $contact_id));
                 }
                 break;
             case 'organization':
                 echo json_encode($model->updateOrganization($api_url, $user_id, $request->getQuery('organization')));
                 break;
             case 'location_type':
                 echo json_encode($model->updateLocationTypes($api_url, $user_id, $request->getQuery('location_types')));
                 break;
             case 'image':
                 $File = $this->params()->fromFiles('image');
                 if ($File['error'] == 0 && $File['size'] > 0) {
                     $S3 = new ImageS3();
                     $data = $S3->uploadFiles($_FILES['image'], "Media", array(), array('Media' => 100, 'Media_thumb' => '138x108\\>\\!'));
                     if (is_array($data) && count($data) > 0) {
                         $imageData = array();
                         $imageData['user_id'] = $user_id;
                         $imageData['media_url'] = $data['Media'];
                         $imageData['media_type'] = 1;
                         $imageData['media_title'] = trim($request->getPost('media_title'));
                         //$imageData['media_description'] = addslashes(trim($request->getPost('media_description')));
                         $imageData['media_description'] = addslashes(trim($request->getPost('media_title')));
                         $imageData['created_by'] = $user_id;
                         $imageData['updated_date'] = date('Y-m-d h:i:s');
                         $imageData['updated_by'] = $user_id;
                         $imageData['status_id'] = 5;
                         if ($request->getPost('id') != "") {
                             $res = $api->curl($api_url . "/api/media/" . $request->getPost('id') . "/", $imageData, "PUT");
                         } else {
                             $res = $api->curl($api_url . "/api/media/", $imageData, "POST");
                         }
                         if ($res->getStatusCode() == 200 || $res->getStatusCode() == 201) {
                             $image_res = json_decode($res->getBody(), true);
                             echo json_encode(array('status' => 1, 'msg' => 'Image uploaded successfully..!!', 'id' => $image_res['id'], 'title' => $image_res['media_title'], 'media_description' => $image_res['media_description'], 'url' => $data['Media_thumb']));
                         } else {
                             echo json_encode(array('status' => 0, 'msg' => 'Failed to upload image..!!', 'code' => $res));
                         }
                     } else {
                         echo json_encode(array('status' => 0, 'msg' => 'Failed to upload image on server..!!', 'code' => $File));
                     }
                 } else {
                     echo json_encode(array('status' => 0, 'msg' => 'Failed to upload image..!!', 'code' => $File));
                 }
                 break;
             case 'avtar':
                 $id = $request->getPost('image');
                 if ($user_id != "" && $id != "") {
                     $media_res = $api->curl($api_url . "/api/media/" . $id . "/", array(), "GET");
                     if ($media_res->getStatusCode() == 200) {
                         $media = json_decode($media_res->getBody(), true);
                         $file = explode('/', $media['media_url']);
                         $fileName = "./public/uploads/" . end($file);
                         file_put_contents($fileName, fopen($media['media_url'], 'r'));
                         try {
                             $S3 = new ImageS3();
                             $data = $S3->uploadFile($fileName, array('Avtars' => '378x378'));
                         } catch (\Exception $e) {
                             echo json_encode(array('status' => 0, 'msg' => 'Failed to update avtar image..!!'));
                             exit;
                         }
                         $temp = $api->curl($api_url . "/api/spusers/" . $user_id . "/", array(), "GET");
                         $avtar = json_decode($temp->getBody(), true);
                         $avtar['avtar_url'] != '' ? $S3->deleteFile(str_replace('https://ovessence.s3.amazonaws.com/', '', $avtar['avtar_url'])) : '';
                         $res = $api->curl($api_url . "/api/spusers/" . $user_id . "/", array('avtar_url' => $data['Avtars'], 'user_type_id' => 3), "PUT");
                         if ($res->getStatusCode() == 200 || $res->getStatusCode() == 201) {
                             echo json_encode(array('status' => 1, 'msg' => 'Avtar image changed successfully..!!', 'image_url' => $data['Avtars']));
                         } else {
                             echo json_encode(array('status' => 0, 'msg' => 'Failed to update avtar image..!!', 'errors' => json_decode($res->getBody(), true)));
                         }
                     }
                 }
                 break;
             case 'delete_image':
                 $id = $request->getPost('image');
                 $media_res = $api->curl($api_url . "/api/media/" . $id . "/", array(), "GET");
                 if ($media_res->getStatusCode() == 200) {
                     $media = json_decode($media_res->getBody(), true);
                     $del_res = $api->curl($api_url . "/api/media/" . $id . "/", array(), "DELETE");
                     if ($del_res->getStatusCode() == 204) {
                         $S3 = new ImageS3();
                         $media['media_url'] != '' ? $S3->deleteFile(str_replace('https://ovessence.s3.amazonaws.com/', '', $media['media_url'])) : '';
                         echo json_encode(array('status' => 1, 'msg' => 'Image deleted successfully..!!'));
                     } else {
                         echo json_encode(array('status' => 0, 'msg' => 'Failed to delete image..!!'));
                     }
                 } else {
                     echo json_encode(array('status' => 0, 'msg' => 'No image found..!!'));
                 }
                 break;
             case 'delete_video':
                 $id = $request->getPost('video');
                 $media_res = $api->curl($api_url . "/api/media/" . $id . "/", array(), "GET");
                 if ($media_res->getStatusCode() == 200) {
                     $media = json_decode($media_res->getBody(), true);
                     $del_res = $api->curl($api_url . "/api/media/" . $id . "/", array(), "DELETE");
                     if ($del_res->getStatusCode() == 204) {
                         $media['media_url'] != '' ? @unlink($media['media_url']) : '';
                         echo json_encode(array('status' => 1, 'msg' => 'Video deleted successfully..!!'));
                     } else {
                         echo json_encode(array('status' => 0, 'msg' => 'Failed to delete video..!!'));
                     }
                 } else {
                     echo json_encode(array('status' => 0, 'msg' => 'No video found..!!'));
                 }
                 break;
             case 'delete_avtar':
                 $details = $model->getSPDetails($api_url, $session->userid);
                 if (isset($details['avtar_url']) && $details['avtar_url'] != '') {
                     $S3 = new ImageS3();
                     $res = $S3->deleteFile(str_replace('https://ovessence.s3.amazonaws.com/', '', $details['avtar_url']));
                     if ($model->updateData($api_url, array('avtar_url' => ''), $session->userid)) {
                         echo json_encode(array('status' => 1, 'msg' => 'Avtar image deleted successfully..!!', 'code' => $res));
                     } else {
                         echo json_encode(array('status' => 0, 'msg' => 'Failed to delete avtar image..!!'));
                     }
                 } else {
                     echo json_encode(array('status' => 0, 'msg' => 'No image found..!!'));
                 }
                 break;
             case 'video':
                 $total = count($model->getSPMedia($api_url, $user_id, 2));
                 $subscriptionDetails = $common->getSubscriptiondetails($api_url, '', true);
                 $video_limit = $subscriptionDetails['video_limit']['limit'];
                 if ($total < $video_limit) {
                     $renameUpload = new \Zend\Filter\File\RenameUpload(array('target' => "./public/uploads/", 'randomize' => true, 'use_upload_name' => true));
                     if ($fileDetails = $renameUpload->filter($_FILES['video'])) {
                         $filePath = $fileDetails['tmp_name'];
                         // check video orientation and rotate if needed
                         /* exec("mediainfo ".$fileDetails['tmp_name']." | grep Rotation", $mediaInfo);
                                                       var_dump($mediaInfo); exit;
                         
                                                       if (is_array($mediaInfo) && count($mediaInfo)>0) {
                                                       $tempPath = explode("/", $fileDetails['tmp_name']);
                                                       $filePath = "./public/uploads/new_".end($tempPath);
                                                       exec('ffmpeg -i '.$fileDetails['tmp_name'].' -vf "transpose=1" -strict -2 '.$filePath, $output, $response);
                                                       ($response == '0')?@unlink($fileDetails['tmp_name']):'';
                                                       } */
                         $videoData = array();
                         $videoData['user_id'] = $user_id;
                         $videoData['media_url'] = $filePath;
                         $videoData['media_title'] = trim($request->getPost('media_title'));
                         //$videoData['media_description'] = addslashes(trim($request->getPost('media_description')));
                         $videoData['media_description'] = addslashes(trim($request->getPost('media_title')));
                         $videoData['created_by'] = $user_id;
                         $videoData['updated_date'] = date('Y-m-d h:i:s');
                         $videoData['updated_by'] = $user_id;
                         $videoData['status_id'] = 5;
                         /* $length = exec("ffmpeg -i /var/www/html/ovessence".str_replace('.','',$fileDetails['tmp_name'])." 2>&1 | grep Duration | cut -d ' ' -f 4 | sed s/,//'");
                            echo var_dump($length); exit; */
                         echo json_encode($model->updateSPMedia($api_url, $videoData, 2, $request->getPost('id')));
                     } else {
                         echo json_encode(array('status' => 0, 'msg' => 'Unable to upload video..!!'));
                     }
                 } else {
                     echo json_encode(array('status' => 0, 'msg' => 'You have already uploaded the maximum number of videos (' . $video_limit . ') allowed by your subscription..!!'));
                 }
                 break;
             case 'workdays':
                 //echo '<pre>'; print_r($request->getQuery()); exit;
                 $id = $request->getQuery('id');
                 $start_time = $request->getQuery('start_time');
                 $end_time = $request->getQuery('end_time');
                 $lunch_start_time = $request->getQuery('lunch_start_time');
                 $lunch_end_time = $request->getQuery('lunch_end_time');
                 $address_id = $request->getQuery('address_id');
                 $mode = 'add';
                 foreach ($start_time as $key => $value) {
                     $data = array();
                     $mode = isset($id[$key]) && $id[$key] != '' && $mode == 'add' ? 'edit' : $mode;
                     $data['start_time'] = $value != '' ? date('H:i:s', strtotime($value)) : '00:00:00';
                     $data['end_time'] = $end_time[$key] != '' ? date('H:i:s', strtotime($end_time[$key])) : '00:00:00';
                     $data['lunch_start_time'] = $lunch_start_time[$key] != '' ? date('H:i:s', strtotime($lunch_start_time[$key])) : '00:00:00';
                     $data['lunch_end_time'] = $lunch_end_time[$key] != '' ? date('H:i:s', strtotime($lunch_end_time[$key])) : '00:00:00';
                     $data['address_id'] = $address_id[$key] != '' ? $address_id[$key] : null;
                     $data['days_id'] = $key;
                     $data['user_id'] = $user_id;
                     if ($mode == 'edit') {
                         $data['id'] = $id[$key] == "" ? $id[$key - 1] + 1 : $id[$key];
                         $wk_res = $api->curl($api_url . "/api/sp_availability/?user_id=" . $user_id, $data, "PUT");
                     } else {
                         $wk_res = $api->curl($api_url . "/api/sp_availability/?user_id=" . $user_id, $data, "POST");
                     }
                     if ($wk_res->getStatusCode() != 200 && $wk_res->getStatusCode() != 201) {
                         echo json_encode(array('status' => 0, 'msg' => 'Failed to update workdays..!!', 'error' => json_decode($wk_res->getBody(), true), 'workdays' => $model->getSPWorkdays($user_id, $api_url)));
                         exit;
                     }
                 }
                 if ($request->getQuery('delay_id') != "") {
                     $delay_res = $api->curl($api_url . "/api/appointment_delay_list/" . $request->getQuery('delay_id') . "/", array('user_id' => $user_id, 'delay_time' => $request->getQuery('appointment_delay')), "PUT");
                 } else {
                     $delay_res = $api->curl($api_url . "/api/appointment_delay_list/", array('user_id' => $user_id, 'delay_time' => $request->getQuery('appointment_delay')), "POST");
                 }
                 if ($delay_res->getStatusCode() != 200 && $delay_res->getStatusCode() != 201) {
                     echo json_encode(array('status' => 0, 'msg' => 'Failed to update appointment delay time..!!', 'workdays' => $model->getSPWorkdays($user_id, $api_url)));
                 } else {
                     echo json_encode(array('status' => 1, 'msg' => 'Workdays updated successfully..!!', 'error' => json_decode($wk_res->getBody(), true), 'workdays' => $model->getSPWorkdays($user_id, $api_url)));
                 }
                 break;
             case 'sp_address':
                 //echo json_encode(array('status' => 0, 'msg' => 'here')); exit;
                 if ($request->getPost('layout') == 'true') {
                     $view = new viewModel(array('states' => $common->getstatesByCountry($api_url), 'countries' => $common->getCountries($api_url), 'location_types' => $model->getLocationTypes($api_url), 'id' => $request->getPost('id')));
                     $view->setTemplate('application/practitioner/workplaceaddress.phtml');
                     $printData = $this->getServiceLocator()->get('viewrenderer')->render($view);
                     echo json_encode(array('layout' => $printData));
                     exit;
                 }
                 $address_data = array();
                 $address_data['user_type'] = 'sp';
                 $address_data['user_id'] = $user_id;
                 $address_id = $request->getQuery('address_id');
                 trim($request->getQuery('street1_address')) != "" ? $address_data['street1_address'] = trim($request->getQuery('street1_address')) : '';
                 trim($request->getQuery('zip_code')) != "" ? $address_data['zip_code'] = trim($request->getQuery('zip_code')) : '';
                 trim($request->getQuery('city')) != "" ? $address_data['city'] = trim($request->getQuery('city')) : '';
                 trim($request->getQuery('country_id')) != "" ? $address_data['country_id'] = trim($request->getQuery('country_id')) : '';
                 trim($request->getQuery('state_id')) != "" ? $address_data['state_id'] = trim($request->getQuery('state_id')) : '';
                 trim($request->getQuery('location_type_id')) != "" ? $address_data['location_type_id'] = trim($request->getQuery('location_type_id')) : '';
                 echo json_encode($model->updateSPAddress($api_url, $address_data, $address_id, $session->userid));
                 break;
             case 'remove_sp_address':
                 $address_id = $request->getPost('id');
                 echo json_encode($model->deleteSPAddress($api_url, $address_id, $session->userid));
                 break;
             case 'invite':
                 //if ($request->getPost('user') != "" && $request->getPost('email') != "") {
                 if ($request->getPost('email') != "") {
                     $common = new Common();
                     if ($template = $common->emailTemplate($api_url, 5)) {
                         $user_details = $model->getSPDetails($api_url, $session->userid);
                         $mail = new Message();
                         $transport = new \Zend\Mail\Transport\Sendmail();
                         $html = new MimePart(stripslashes(preg_replace('/{{user_name}}/i', '<strong>' . $user_details['first_name'] . ' ' . $user_details['last_name'] . '</strong>', $template['content'])));
                         $html->type = "text/html";
                         $body = new MimeMessage();
                         $body->setParts(array($html));
                         $mail->setBody($body)->setFrom($template['fromEmail'], 'Ovessence')->addTo($request->getPost('email'), '')->setSubject($template['subject']);
                         $transport->send($mail);
                         echo json_encode(array('status' => 1, 'msg' => 'Invitation sent to the email address..!!'));
                     } else {
                         echo json_encode(array('status' => 0, 'msg' => 'Unable to find mail template..!!'));
                     }
                 } else {
                     echo json_encode(array('status' => 0, 'msg' => 'Unable to send invitation..!!'));
                 }
                 break;
         }
     }
     exit;
 }
 public function saveeditphotosAction()
 {
     $datos = $this->getRequest()->getPost();
     $dir = $datos['dir'];
     $files = $this->getRequest()->getFiles()->toArray();
     $ruta = './public/fotografias/' . $dir . '/';
     if (!file_exists($ruta)) {
         mkdir($ruta);
     }
     $nombrePhoto = '';
     $filter = new \Zend\Filter\File\RenameUpload($ruta);
     $filter->setUseUploadName(true);
     $cont = 0;
     foreach ($files['proyecto-fotos'] as $file) {
         switch ($file['type']) {
             case 'image/jpeg':
                 $nombrePhoto = date('Ymd_Gis') . $cont . 'jpg';
                 break;
             case 'image/png':
                 $nombrePhoto = date('Ymd_Gis') . $cont . 'png';
                 break;
         }
         $file['name'] = $nombrePhoto;
         $filter->filter($file);
         $cont += 1;
     }
     return new JsonModel(array('Result' => 'OK'));
 }
 /**
  * carga la vista de crear proyecto y recibe los datos post para crear proyecto
  * @return \Zend\View\Model\ViewModel
  */
 public function crearAction()
 {
     if ($this->getRequest()->isPost()) {
         $datos = $this->getRequest()->getPost();
         $project = new proyecto();
         $proyecto_e = new ProyectoEducacion();
         $estado = $this->em()->getRepository('\\Login\\Model\\Entity\\Estado')->find(1);
         $eje = $this->em()->getRepository('\\Login\\Model\\Entity\\Eje')->find(2);
         $project->setEstado($estado);
         $project->setEje($eje);
         $project->setProyectoPathfotos('pendiente');
         $project->setProyectoAnio($datos["vigencia"]);
         $project->setProyectoPresupuesto($datos["valProj"]);
         $proyecto_e->setProyecto($project);
         $proyecto_e->setProyectoeducacionEjecutor($datos["ejecutorP"]);
         $fecha = \DateTime::createFromFormat('d/m/Y', $datos["fechaIni"]);
         $proyecto_e->setProyectoeducacionFechainicio($fecha);
         $proyecto_e->setProyectoeducacionNumero($datos["numeroP"]);
         $proyecto_e->setProyectoeducacionNombre($datos["nombreP"]);
         $proyecto_e->setProyectoeducacionPlazoejecucion($datos["plazoEjec"]);
         $proyecto_e->setProyectoeducacionObjetivo($datos["objetivo"]);
         $proyecto_e->setProyectoeducacionPerfilbeneficiario($datos["perfilBen"]);
         $proyecto_e->setProyectoeducacionCupos($datos["cupos"]);
         $this->dbh()->insertObj($proyecto_e);
         $files = $this->getRequest()->getFiles()->toArray();
         $ruta = './public/fotografias/' . $project->getProyectoId() . '/';
         if (!file_exists($ruta)) {
             mkdir($ruta);
         }
         $filter = new \Zend\Filter\File\RenameUpload($ruta);
         $filter->setUseUploadName(true);
         foreach ($files['proyecto-fotos'] as $file) {
             $filter->filter($file);
         }
         return $this->forward()->dispatch('Educacion\\Controller\\index', array('action' => 'ver', 'educacion' => $proyecto_e));
     } else {
         $this->layout('layout/educacion');
         $this->layout()->titulo = '.::Crear Proyecto:.';
         $adapter = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
         $formEducacion = new FormularioEducacion($adapter);
         return new ViewModel(array('formEducacion' => $formEducacion));
     }
 }
Esempio n. 7
0
 public function uploadImageCatalog($imageData = array())
 {
     if (!empty($imageData)) {
         $fileName = 'catalog_' . time() . '.jpg';
         $dir = UPLOAD_PATH_IMG;
         $dirFileName = $dir . '/' . $fileName;
         $filter = new \Zend\Filter\File\RenameUpload($dirFileName);
         if ($filter->filter($imageData)) {
             $options = array('max_width' => 380, 'max_height' => 380, 'jpeg_quality' => 100);
             $this->createImageThumbnail($dirFileName, $dir . '/thumb_catalog', $options);
             return $fileName;
         }
     }
     return false;
 }
 /**
  * 
  * @return \Zend\View\Model\JsonModel
  */
 public function saveReporteViaAction()
 {
     $formulario = $this->getRequest()->getPost();
     $foto = $this->getRequest()->getFiles()->toArray();
     $type = $foto['photo']['type'];
     $nameFile = '';
     switch ($type) {
         case 'image/png':
             $nameFile = date('Ymd_Gis') . '.png';
             break;
         case 'image/jpeg':
             $nameFile = date('Ymd_Gis') . '.jpg';
             break;
     }
     $reporte = new \Login\Model\Entity\ReporteVia();
     $barrio = $this->dbh()->selectAllById(array("barrioId" => $formulario['barrios']), '\\Login\\Model\\Entity\\Barrio');
     $reporte->setReporteviaDireccion($formulario['direccion']);
     $reporte->setReporteviaObservacion($formulario['observacion']);
     $reporte->setBarrio($barrio[0]);
     $reporte->setReporteviasFotos($nameFile);
     $reporte->setReporteviaFecha(new \DateTime(date('Y-m-d h:i:s')));
     if ($this->dbh()->insertObj($reporte)) {
         $foto['photo']['name'] = $nameFile;
         $filter = new \Zend\Filter\File\RenameUpload('./public/fotografias/Reports/');
         $filter->setUseUploadName(true);
         $filter->filter($foto['photo']);
         return new JsonModel(array("Result" => "OK"));
     } else {
         return new JsonModel(array("Result" => "NOK"));
     }
 }
Esempio n. 9
0
 public function editAction()
 {
     $id = (int) $this->params()->fromRoute('id', 0);
     if (!$id) {
         return $this->redirect()->toRoute('admin/media');
     }
     $media = $this->getMediaTable()->getMedia($id);
     if ($media == false) {
         $this->flashMessenger()->addErrorMessage('Media not found..!!');
         return $this->redirect()->toRoute('admin/media');
     }
     $form = new MediaForm($this->getServiceLocator()->get('Admin\\Model\\UsersTable'), $this->getServiceLocator()->get('Admin\\Model\\StatusTable'));
     $old_media = $media->media_url;
     $form->bind($media);
     $form->get('submit')->setAttribute('value', 'Edit');
     $request = $this->getRequest();
     if ($request->isPost()) {
         $File = $this->params()->fromFiles('media_url');
         // Make certain to merge the files info!
         $post = array_merge_recursive($request->getPost()->toArray(), array('media_url' => $File['name']));
         $form->setInputFilter($media->getInputFilter());
         $form->setData($post);
         $adapter = new \Zend\File\Transfer\Adapter\Http();
         if ($form->isValid()) {
             $S3 = new ImageS3();
             $formData = $form->getData();
             if ($post['media_type'] == '1') {
                 if ($File['name'] != "") {
                     $validator = new IsImage();
                     if ($validator->isValid($File['tmp_name'])) {
                         /* Image uploading code starts */
                         $size = new Size(array('min' => 200, 'max' => 20000000));
                         $adapter->setValidators(array($size), $File['name']);
                         if (!$adapter->isValid()) {
                             $dataError = $adapter->getMessages();
                             return array('form' => $form, 'file_errors' => $dataError);
                         } else {
                             $data = $S3->uploadFiles($_FILES['media_url'], "Media", array(), array('Media' => 100, 'Media_thumb' => 20));
                             if (is_array($data) && count($data) > 0) {
                                 $formData->media_url = $data['Media'];
                                 // deleting old image
                                 $S3->deleteFile(str_replace('https://ovessence.s3.amazonaws.com/', '', $old_image));
                                 $S3->deleteFile(str_replace('https://ovessence.s3.amazonaws.com/', '', str_replace('Media', 'Media_thumb', $old_image)));
                             }
                         }
                         /* Image uploading code ends */
                     } else {
                         return array('form' => $form, 'file_errors' => $validator->getMessages());
                     }
                 } else {
                     $formData->media_url = $old_media;
                 }
             } else {
                 if ($post['media_type'] == '2') {
                     if ($File['name'] != "") {
                         $renameUpload = new \Zend\Filter\File\RenameUpload(array('target' => "./public/uploads/", 'randomize' => true, 'use_upload_name' => true));
                         if ($fileDetails = $renameUpload->filter($_FILES['media_url'])) {
                             $filePath = $fileDetails['tmp_name'];
                             // check video orientation and rotate if needed
                             /*exec("mediainfo " . $fileDetails['tmp_name'] . " | grep Rotation", $mediaInfo);
                             
                                                         if (is_array($mediaInfo) && count($mediaInfo) > 0) {
                                                             $tempPath = explode("/", $fileDetails['tmp_name']);
                                                             $filePath = "./public/uploads/new_" . end($tempPath);
                                                             exec('ffmpeg -i ' . $fileDetails['tmp_name'] . ' -vf "transpose=1" -strict -2 ' . $filePath, $output, $response);
                                                             ($response == '0') ? @unlink($fileDetails['tmp_name']) : '';
                                                         }*/
                             $session = new Container('vimeo');
                             $formData->media_url = $session->file = $filePath;
                             $session->mode = 'write';
                             $session->returnUrl = $this->url()->fromRoute('admin/media');
                             $session->old_video = $old_media;
                             $session->media_id = $this->getMediaTable()->saveMedia($form->getData());
                             if ($formData->status_id == 9) {
                                 return $this->redirect()->toRoute('admin/media', array('action' => 'vimeologin'));
                             }
                         } else {
                             return array('form' => $form, 'file_errors' => $adaptor->getMessages());
                         }
                     } else {
                         $formData->media_url = $old_media;
                     }
                 }
             }
             $this->getMediaTable()->saveMedia($form->getData());
             $this->flashMessenger()->addSuccessMessage('Media updated successfully..!!');
             // Redirect to list of banners
             return $this->redirect()->toRoute('admin/media');
         }
     }
     return array('id' => $id, 'media' => $media, 'errors' => $this->errors, 'form' => $form);
 }