private function editProfile() { if ($this->registry->getObject('authenticate')->isLoggedIn() == true) { $user = $this->registry->getObject('authenticate')->getUser()->getUserID(); if (isset($_POST) && count($_POST) > 0) { $profile = new ProfileModel($this->registry, $user); $profile->setBio($this->registry->getObject('db')->sanitizeData($_POST['bio'])); $profile->setName($this->registry->getObject('db')->sanitizeData($_POST['name'])); $profile->setGender($this->registry->getObject('db')->sanitizeData($_POST['gender']), false); $profile->setDOB($this->registry->getObject('db')->sanitizeData($_POST['dob']), false); if (isset($_FILES['profile_pic'])) { require_once 'mediaManager.php'; $im = new ImageManager(); $image = $im->loadFromPost('profile_pic', $this->registry->getSetting('upload_path') . 'profile/' . $profile->getUsername() . '/', time()); //$images .= $image; if ($image == true) { $im->resizeScale(50); $im->save($this->registry->getSetting('upload_path') . 'profile/' . $im->getName()); $profile->setPhoto($im->getName()); } //$this->registry->redirectUser('profile/edit/'.$profile->getID(), 'Image Saved', 'Image upload success'); } else { $this->registry->errorPage('Error', 'Image uploading failed'); } $profile->save(); $this->registry->redirectUser('profile/view', 'Profile saved', 'The changes to your profile have been saved.'); //array('profile', 'view', 'edit') } else { //Show the edit form $this->registry->getObject('template')->buildFromTemplate('header.php', 'profile_info_edit.php', 'footer.php'); $profile = new ProfileModel($this->registry, $user); $profile->toTags('p_'); } } else { $this->registry->errorPage('Error', 'Please login to continue'); } }
function form() { $message = ''; $validFiles = array('jpg', 'jpge', 'jpeg', 'gif', 'png'); try { if (!$_POST['varName']) { throw new Exception('Información incompleta'); } if (!$_POST['idReg'] && !array_key_exists('uploadImage', $_FILES)) { throw new Exception('Debe incluir una imágen en un nuevo registro'); } elseif ($_POST['idReg'] && !$_POST['varImage'] && !array_key_exists('uploadImage', $_FILES)) { throw new Exception('Debe incluir una imágen en un nuevo registro'); } if (!$_POST['idReg'] && !array_key_exists('uploadImageFront', $_FILES)) { throw new Exception('Debe incluir una imágen en un nuevo registro'); } elseif ($_POST['idReg'] && !$_POST['varImageFront'] && !array_key_exists('uploadImageFront', $_FILES)) { throw new Exception('Debe incluir una imágen en un nuevo registro'); } if (array_key_exists('uploadImage', $_FILES) && $_FILES['uploadImage']['name']) { $fileInfo = pathinfo($_FILES['uploadImage']['name']); if ($_FILES['uploadImage']['name'] && !in_array($fileInfo['extension'], $validFiles)) { throw new Exception('Solo se permiten imágenes de formato JPG, GIF y PNG'); } $varImage = friendlyUrl($fileInfo['filename']) . '.' . $fileInfo['extension']; $dest = MALETEKPL__PLUGIN_DIR . 'resources' . DS . 'items' . DS . $varImage; if (!move_uploaded_file($_FILES['uploadImage']['tmp_name'], $dest)) { throw new Exception('Error al subir imagen Principal'); } include_once '../../libs/ImageManager.php'; $img = new ImageManager($dest); $img->thumbnail(400, 400); $img->save(); } else { $varImage = $_POST['varImage']; } if (array_key_exists('uploadImageFront', $_FILES) && $_FILES['uploadImageFront']['name']) { $fileInfo = pathinfo($_FILES['uploadImageFront']['name']); if ($_FILES['uploadImageFront']['name'] && !in_array($fileInfo['extension'], $validFiles)) { throw new Exception('Solo se permiten imágenes de formato JPG, GIF y PNG'); } $varImageFront = friendlyUrl($fileInfo['filename']) . '.' . $fileInfo['extension']; $dest = MALETEKPL__PLUGIN_DIR . 'resources' . DS . 'items' . DS . $varImageFront; if (!move_uploaded_file($_FILES['uploadImageFront']['tmp_name'], $dest)) { throw new Exception('Error al subir imagen Frontal'); } include_once '../../libs/ImageManager.php'; $img = new ImageManager($dest); $img->thumbnail(400, 400); $img->save(); } else { $varImageFront = $_POST['varImageFront']; } $data = array('varName' => $_POST['varName'], 'varContent' => $_POST['varContent'], 'intRows' => $_POST['intRows'], 'varImage' => $varImage, 'varImageFront' => $varImageFront, 'dateUpdate' => date('Y-m-d H:i:s')); if ($_POST['idReg']) { $this->DB->update($this->table_name, $data, 'id="' . $_POST['idReg'] . '"'); } else { $this->DB->insert($this->table_name, $data); } $message = '<div class="updated">Se guardó la información correctamente</div>'; } catch (Exception $ex) { $message = '<div class="error">' . $ex->getMessage() . '</div>'; } exit($message); }