public function insertPhotoResize($path, $file, $user_id, $resizeW, $resizeH) { if (!$file) { return false; } $thumb1 = new EPhpThumb(); $thumb1->init(); $thumb1->create($path . $user_id . '/' . $file->name)->resize($resizeW, $resizeH)->save($path . $user_id . '/' . $resizeW . 'x' . $resizeH . $file->name); return $file->name; }
public function actionResetImage() { $uploadPath = YiiBase::getPathOfAlias('webroot') . '/files/products'; @set_time_limit(0); $items = ProductItem::model()->findAll(); foreach ($items as $item) { $thumbsPath = $uploadPath; $filename = $item->image; @unlink($thumbsPath . '/thumb_' . $filename); // thumbnails image Yii::import("ext.EPhpThumb.EPhpThumb"); $thumb = new EPhpThumb(); $thumb->init(); //this is needed $thumb->create($uploadPath . '/' . $filename)->adaptiveResize(Yii::app()->getModule('products')->widthThumb, Yii::app()->getModule('products')->heightThumb)->save($thumbsPath . '/thumb_' . $filename); } echo 'Done!'; }
public function actionAddCustomPhoto($id) { $model = $this->loadModel($id); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); $aAllBannerSize = Banners::getHomeBannerSize(); $aBannerSize = $aAllBannerSize[$model->place_holder_id]; if (isset($_POST['Banners'])) { $model->attributes = $_POST['Banners']; $model->image = CUploadedFile::getInstance($model, 'image'); $model->scenario = 'addCustomPhoto'; if ($model->validate()) { $ext = $model->image->getExtensionName(); $file_name = 'banner_' . $model->place_holder_id; $model->large_image = $file_name . '.' . $ext; $model->thumb_image = 'thumb_' . $file_name . '.' . $ext; if ($model->save()) { $model->image = EUploadedImage::getInstance($model, 'image'); //$model->image->maxWidth = $aBannerSize['width']; //$model->image->maxHeight = $aBannerSize['height']; /*$model->image->thumb = array( 'maxWidth' => $aBannerSize['width'], 'maxHeight' => $aBannerSize['height'], 'dir' => 'thumbs', 'prefix' => 'thumb_', );*/ $model->image->saveAs(Yii::getPathOfAlias('webroot') . '/upload/admin/homeBanner/' . $file_name . '.' . $ext); $thumb = new EPhpThumb(); $thumb->init(); $thumb->create(Yii::getPathOfAlias('webroot') . '/upload/admin/homeBanner/' . $file_name . '.' . $ext)->resize($aBannerSize['width'], $aBannerSize['height'])->save(Yii::getPathOfAlias('webroot') . '/upload/admin/homeBanner/thumbs/thumb_' . $file_name . '.' . $ext); $this->redirect(array('/admin/manageBanner')); } } } $this->render('addCustomPhoto', array('model' => $model, 'bannerSize' => $aBannerSize)); }
/** * Creates a new EThumbnail object allowing to manipulate the image file provided via $filePath * @param string $filePath the image file path. * @return PhpThumb object */ public function create($filePath) { return new EThumbnail(EPhpThumb::thumbFactory($filePath)); }
/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ public function actionUpdate($id) { $baseScriptUrl = Yii::app()->assetManager->publish(dirname(__FILE__) . '/../assets'); Yii::app()->getClientScript()->registerCssFile($baseScriptUrl . '/live.css'); $model = $this->loadModel($id); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['LiveItem'])) { $model->attributes = $_POST['LiveItem']; if (isset($_POST['LiveItem']['categories'])) { $model->categories = implode(',', $_POST['LiveItem']['categories']); } $fileUpload = CUploadedFile::getInstance($model, 'image'); if (isset($fileUpload) && $model->validate()) { $uploadPath = YiiBase::getPathOfAlias('webroot') . '/files/live'; //Yii::app()->basePath . '/../jlwebroot/upload'; if (!is_dir($uploadPath)) { @mkdir($uploadPath); @chmod($uploadPath, 0777); } // Delete old image if ($model->image) { @unlink($uploadPath . '/' . $model->image); @unlink($uploadPath . '/thumb_' . $model->image); } $filename = time() . mt_rand(0, 0xfff) . '.' . $fileUpload->getExtensionName(); $fileUpload->saveAs($uploadPath . '/' . $filename); /** * @todo chưa có setting cho thumbnail * */ // thumbnails image $thumbsPath = $uploadPath; Yii::import("ext.EPhpThumb.EPhpThumb"); $thumb = new EPhpThumb(); $thumb->init(); //this is needed $thumb->create($uploadPath . '/' . $filename)->adaptiveResize(Yii::app()->getModule('live')->widthThumb, Yii::app()->getModule('live')->heightThumb)->save($thumbsPath . '/thumb_' . $filename); $model->image = $filename; } if ($model->validate() && $model->removeImage && $model->image) { // Delete old image if ($model->image) { @unlink($uploadPath . '/' . $model->image); @unlink($uploadPath . '/thumb_' . $model->image); } $model->image = ''; } $model->modified = date('Y-m-d H:i:s', time()); if ($model->save()) { $this->redirect(array('admin')); } } $categories = LiveCategory::model()->roots()->findAll(); $this->render('form', array('model' => $model, 'categories' => $categories)); }
public function actionUpdateprofiletab1($id) { $model = $this->loadModel($id); $user = User::model()->findByPk($model->student_transaction_user_id); $info = StudentInfo::model()->findByPk($model->student_transaction_student_id); $address = StudentAddress::model()->findByPk($model->student_transaction_student_address_id); $photo = StudentPhotos::model()->findByPk($model->student_transaction_student_photos_id); $lang = LanguagesKnown::model()->findByPk($model->student_transaction_languages_known_id); $this->performAjaxValidation(array($info, $model)); if (isset($_POST['StudentTransaction'])) { StudentTransaction::model()->updateByPk($id, array('student_transaction_nationality_id' => $_POST['StudentTransaction']['student_transaction_nationality_id'], 'student_academic_term_period_tran_id' => $_POST['StudentTransaction']['student_academic_term_period_tran_id'], 'student_academic_term_name_id' => $_POST['StudentTransaction']['student_academic_term_name_id'], 'student_transaction_course_id' => $_POST['StudentTransaction']['student_transaction_course_id'])); $adm = date("Y-m-d", strtotime($_POST['StudentInfo']['student_adm_date'])); $birthdate = NULL; if ($_POST['StudentInfo']['student_dob'] != '') { $birthdate = date("Y-m-d", strtotime($_POST['StudentInfo']['student_dob'])); } StudentInfo::model()->updateByPk($model->student_transaction_student_id, array('student_adm_date' => $adm, 'student_enroll_no' => $_POST['StudentInfo']['student_enroll_no'], 'title' => $_POST['StudentInfo']['title'], 'student_first_name' => $_POST['StudentInfo']['student_first_name'], 'student_last_name' => $_POST['StudentInfo']['student_last_name'], 'student_gender' => $_POST['StudentInfo']['student_gender'], 'student_mobile_no' => $_POST['StudentInfo']['student_mobile_no'], 'student_dob' => $birthdate, 'student_bloodgroup' => $_POST['StudentInfo']['student_bloodgroup'], 'student_email_id_1' => $_POST['StudentInfo']['student_email_id_1'])); LanguagesKnown::model()->updateByPk($model->student_transaction_languages_known_id, array('languages_known1' => $_POST['LanguagesKnown']['languages_known1'], 'languages_known2' => $_POST['LanguagesKnown']['languages_known2'])); if (isset($_POST['StudentPhotos'])) { $old_photo = $photo->student_photos_path; $photo->student_photos_path = CUploadedFile::getInstance($photo, 'student_photos_path'); if ($photo->student_photos_path == null) { $valid_photo = true; } else { $valid_photo = $photo->validate(); } if ($valid_photo) { if ($photo->student_photos_path != null) { $newfname = ''; $ext = substr(strrchr($photo->student_photos_path, '.'), 1); //following thing done for deleting previously uploaded photo $photo1 = $old_photo; $dir1 = Yii::getPathOfAlias('webroot') . '/college_data/stud_images/'; if (file_exists($dir1 . $photo1) && $photo1 != 'no-images') { chmod($dir1 . $photo1, 0777); unlink($dir1 . $photo1); } if ($ext != null) { $newfname = $info->student_enroll_no . '.' . $ext; $photo->student_photos_path->saveAs(Yii::getPathOfAlias('webroot') . '/college_data/stud_images/' . ($photo->student_photos_path = $newfname)); } Yii::import("ext.EPhpThumb.EPhpThumb"); $thumb = new EPhpThumb(); $thumb->init(); //this is needed $thumb->create(Yii::getPathOfAlias('webroot') . '/college_data/stud_images/' . ($photo->student_photos_path = $newfname))->resize(500, 500)->save(Yii::getPathOfAlias('webroot') . '/college_data/stud_images/' . $photo->student_photos_path); $photo->save(false); } } } $this->redirect(array('update', 'id' => $id)); } $this->render('updateproftab1', array('model' => $model, 'info' => $info, 'lang' => $lang, 'photo' => $photo)); }
public function actionUpdate($id) { $model = $this->loadModel($id); $old_model = $this->loadModel($id); // Uncomment the following line if AJAX validation is needed $this->performAjaxValidation($model); if (isset($_POST['VisitorPass'])) { $model->attributes = $_POST['VisitorPass']; $model->photo = CUploadedFile::getInstance($model, 'photo'); if ($model->photo == null) { $valid_photo = true; } else { $valid_photo = $model->validate(); } if ($valid_photo) { if ($model->photo == null) { $model->photo = $old_model->photo; } else { $newfname; $ext = substr(strrchr($model->photo, '.'), 1); if ($ext != null) { $newfname = $model->visitor_name . '.' . $ext; $model->photo->saveAs(Yii::getPathOfAlias('webroot') . '/visitors_photo/' . ($model->photo = $newfname)); } Yii::import("ext.EPhpThumb.EPhpThumb"); $thumb = new EPhpThumb(); $thumb->init(); //this is needed $thumb->create(Yii::getPathOfAlias('webroot') . '/visitors_photo/' . $model->photo)->resize(150, 150)->save(Yii::getPathOfAlias('webroot') . '/visitors_photo/' . $model->photo); } $model->save(); $this->redirect(array('new_view', 'id' => $model->pass_no)); } } $this->render('update', array('model' => $model)); }
/** * * @todo RESIZE & CROP * @param type $fileName * @example * $ImageHelper = new ImageHelper(); * @author bb */ public function resizeAndCrop($fileName) { $thumb = new EPhpThumb(); $thumb->init(); $thumb->create(Yii::getPathOfAlias('webroot') . '/' . $this->folder . '/' . $this->file)->adaptiveResize($this->thumbs['width'], $this->thumbs['height'])->save(Yii::getPathOfAlias('webroot') . '/' . $this->folder . '/' . $fileName); }
/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ public function actionUpdate($id) { $model = $this->loadModel($id); $old_model = $this->loadModel($id); // Uncomment the following line if AJAX validation is needed $this->performAjaxValidation($model); if (isset($_POST['PhotoGallery'])) { $model->attributes = $_POST['PhotoGallery']; $model->photo_path = CUploadedFile::getInstance($model, 'photo_path'); if ($model->photo_path == null) { $valid_photo = true; } else { $valid_photo = $model->validate(); } if ($valid_photo) { if ($model->photo_path == null) { $model->photo_path = $old_model->photo_path; } else { $ext = substr(strrchr($model->photo_path, '.'), 1); if ($ext != null) { $model->photo_path->saveAs(Yii::getPathOfAlias('webroot') . '/images/album1/' . $model->photo_path); } //following thing done for deleting previously uploaded photo $photo = $old_model->photo_path; $dir1 = Yii::getPathOfAlias('webroot') . '/images/album1/'; if ($dh = opendir($dir1)) { if (file_exists($dir1 . $photo)) { chmod($dir1 . $photo, 0777); unlink($dir1 . $photo); } } closedir($dh); $dir2 = Yii::getPathOfAlias('webroot') . '/images/album1/album_thumbs/'; if ($dh = opendir($dir2)) { if (file_exists($dir2 . $photo)) { unlink($dir2 . $photo); } } $dir3 = Yii::getPathOfAlias('webroot') . '/images/album1/thumbs/'; if ($dh = opendir($dir3)) { if (file_exists($dir3 . $photo)) { unlink($dir3 . $photo); } } Yii::import("ext.EPhpThumb.EPhpThumb"); $thumb = new EPhpThumb(); $thumb->init(); //this is needed $thumb->create(Yii::getPathOfAlias('webroot') . '/images/album1/' . $model->photo_path)->resize(100, 150)->save(Yii::getPathOfAlias('webroot') . '/images/album1/album_thumbs/' . $model->photo_path); } if ($model->save(false)) { $this->redirect(array('admin')); } } if ($model->save()) { $this->redirect(array('view', 'id' => $model->photo_id)); } } $this->render('update', array('model' => $model)); }
/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ public function actionUpdate($id) { $model = $this->loadModel($id); /* penyesuaian format date dari db ke data yang ditampilkan ke user*/ $format = new CustomFormat(); empty($model->tglditerima) ? $model->tglditerima = null : ($model->tglditerima = $format->formatDbtoDate($model->tglditerima)); empty($model->tglkeluar) ? $model->tglkeluar = null : ($model->tglkeluar = $format->formatDbtoDate($model->tglkeluar)); empty($model->tgllahir_karyawan) ? $model->tgllahir_karyawan = null : ($model->tgllahir_karyawan = $format->formatDbtoDate($model->tgllahir_karyawan)); // $tempcreatetime = $model->create_time; /*---------------------------------------------------------------------------------------------------------*/ $temLogo = $model->photo_karyawan; if (isset($_POST['KKaryawanM'])) { $random = rand(00, 9999999); $model->attributes = $_POST['KKaryawanM']; $model->photo_karyawan = CUploadedFile::getInstance($model, 'photo_karyawan'); $gambar = $model->photo_karyawan; empty($model->tglditerima) ? $model->tglditerima = null : ($model->tglditerima = $format->formatDateForDb($model->tglditerima)); empty($model->tglkeluar) ? $model->tglkeluar = null : ($model->tglkeluar = $format->formatDateForDb($model->tglkeluar)); empty($model->tgllahir_karyawan) ? $model->tgllahir_karyawan = null : ($model->tgllahir_karyawan = $format->formatDateForDb($model->tgllahir_karyawan)); // print_r($model->create_time);exit; if (!empty($model->photo_karyawan)) { $model->photo_karyawan = $random . $model->photo_karyawan; Yii::import("ext.EPhpThumb.EPhpThumb"); $thumb = new EPhpThumb(); $thumb->init(); //this is needed $fullImgName = $model->photo_karyawan; $fullImgSource = Params::pathKaryawanDirectory() . $fullImgName; $fullThumbSource = Params::pathKaryawanDirectory() . 'kecil_' . $fullImgName; if ($model->save()) { if (!empty($model->no_fingerprint)) { $this->insertData($model); } if (!empty($temLogo)) { unlink(Params::pathKaryawanDirectory() . $temLogo); unlink(Params::pathKaryawanDirectory() . 'kecil_' . $temLogo); } $gambar->saveAs($fullImgSource); $thumb->create($fullImgSource)->resize(200, 200)->save($fullThumbSource); $this->redirect(array('view', 'id' => $model->karyawan_id)); } else { Yii::app()->user->setFlash('error', 'Data <strong>Gagal!</strong> disimpan.'); } } else { // $model->create_time = $format->formatDbToDateTime($model->create_time); $model->photo_karyawan = $temLogo; // exit(); if ($model->validate()) { if ($model->save()) { if (!empty($model->no_fingerprint)) { $this->insertData($model); } $this->redirect(array('admin', 'id' => $model->karyawan_id)); } } } } $this->render('update', array('model' => $model)); }
public function actionUpload() { $model = new PhotoGallery(); Yii::import("ext.EAjaxUpload.qqFileUploader"); $folder = Yii::getPathOfAlias('webroot') . '/college_data/gallery/album1/'; // folder for uploaded files $allowedExtensions = array("jpg", "jpeg", "gif", "exe", "mov", "mp4"); //array("jpg","jpeg","gif","exe","mov" and etc... $sizeLimit = 100 * 1024 * 1024; // maximum file size in bytes $uploader = new qqFileUploader($allowedExtensions, $sizeLimit); $result = $uploader->handleUpload($folder); $return = htmlspecialchars(json_encode($result), ENT_NOQUOTES); $fileSize = filesize($folder . $result['filename']); //GETTING FILE SIZE $fileName = $result['filename']; //GETTING FILE NAME Yii::import("ext.EPhpThumb.EPhpThumb"); $thumb = new EPhpThumb(); $thumb->init(); //this is needed $thumb->create(Yii::getPathOfAlias('webroot') . '/college_data/gallery/album1/' . $fileName)->resize(100, 150)->save(Yii::getPathOfAlias('webroot') . '/college_data/gallery/album1/album_thumbs/' . $fileName); $model->created_by = Yii::app()->user->id; $model->photo_desc = "No description"; $model->creation_date = new CDbExpression('NOW()'); $model->photo_path = $fileName; $model->display_status = 0; $model->save(false); echo $return; // it's array }
/** * This action is used to update the profile photo of the employee. */ public function actionUpdateprofilephoto($id) { $emp_trans = EmployeeTransaction::model()->findByPk($id); $info = EmployeeInfo::model()->findByPk($emp_trans->employee_transaction_employee_id); $model = EmployeePhotos::model()->findByPk($emp_trans->employee_transaction_emp_photos_id); //echo $emp_trans->employee_transaction_id; $this->performAjaxValidation($model); if(isset($_POST['EmployeePhotos'])) { $old_photo = $model->employee_photos_path; $model->employee_photos_path = CUploadedFile::getInstance($model,'employee_photos_path'); if($model->employee_photos_path == null) { $valid_photo = true; } else { $valid_photo = $model->validate(); } if($valid_photo) { if($model->employee_photos_path!=null) { $newfname = ''; $ext= substr(strrchr($model->employee_photos_path,'.'),1); //following thing done for deleting previously uploaded photo $photo = $old_photo; $dir1 = Yii::getPathOfAlias('webroot').'/college_data/emp_images/'; if(file_exists($dir1.$photo) && $photo!='no-images'){ unlink($dir1.$photo); } if($ext!=null) { $newfname = $emp_trans->employee_transaction_id."_".$info->employee_first_name.'.'.$ext; $model->employee_photos_path->saveAs(Yii::getPathOfAlias('webroot').'/college_data/emp_images/'.$model->employee_photos_path = $newfname); } Yii::import("ext.EPhpThumb.EPhpThumb"); $thumb=new EPhpThumb(); $thumb->init(); //this is needed $thumb->create(Yii::getPathOfAlias('webroot').'/college_data/emp_images/'.$model->employee_photos_path=$newfname)->resize(500,500)->save(Yii::getPathOfAlias('webroot').'/college_data/emp_images/'.$model->employee_photos_path); $model->save(false); } $this->redirect(array('update','id'=>$id)); } } $this->render('photo_form',array( 'model'=>$model, )); }
public function actionUpdateprofilephoto($id) { $stud_trans = StudentTransaction::model()->findByPk($id); $info = StudentInfo::model()->findByAttributes(array('student_info_transaction_id' => $id)); $model = StudentPhotos::model()->findByPk($stud_trans->student_transaction_student_photos_id); $old_model = StudentPhotos::model()->findByPk($stud_trans->student_transaction_student_photos_id); $this->performAjaxValidation($model); if (isset($_POST['StudentPhotos'])) { $old_photo = $model->student_photos_path; $model->student_photos_path = CUploadedFile::getInstance($model, 'student_photos_path'); if ($model->student_photos_path == null) { $valid_photo = true; } else { $valid_photo = $model->validate(); } if ($valid_photo) { if ($model->student_photos_path != null) { $newfname = ''; $ext = substr(strrchr($model->student_photos_path, '.'), 1); //following thing done for deleting previously uploaded photo $photo = $old_photo; $dir1 = Yii::getPathOfAlias('webroot') . '/stud_images/'; if (file_exists($dir1 . $photo) && $photo != 'no-images') { chmod($dir1 . $photo, 0777); unlink($dir1 . $photo); } if ($ext != null) { $newfname = $info->student_enroll_no . '.' . $ext; $model->student_photos_path->saveAs(Yii::getPathOfAlias('webroot') . '/stud_images/' . ($model->student_photos_path = $newfname)); } Yii::import("ext.EPhpThumb.EPhpThumb"); $thumb = new EPhpThumb(); $thumb->init(); //this is needed $thumb->create(Yii::getPathOfAlias('webroot') . '/stud_images/' . ($model->student_photos_path = $newfname))->resize(500, 500)->save(Yii::getPathOfAlias('webroot') . '/stud_images/' . $model->student_photos_path); $model->save(false); } $this->redirect(array('update', 'id' => $id)); } } $this->render('photo_form', array('model' => $model)); }
/** * Resize image * * @author Lam Huynh * @example $this->_resizeImage('c:\abc\a.jpg', 400, 300) * @return boolean */ public function _resizeImage($filePath, $width, $height) { if (!is_file($filePath)) { return false; } $srcDir = dirname($filePath); $dstDir = $srcDir . DIRECTORY_SEPARATOR . "{$width}x{$height}"; $saveName = $dstDir . DIRECTORY_SEPARATOR . basename($filePath); if (!is_dir($dstDir)) { mkdir($dstDir, 0777, true); } $thumb = new EPhpThumb(); $thumb->init(); $thumb->create($filePath)->adaptiveResize($width, $height)->save($saveName); return is_file($saveName); }
public function actionUpdateCalonKaryawan($id) { $modelp = $this->loadModel($id); $model = new KKaryawanM(); $model->lokasi_id = Params::DEFAULT_LOKASI; $format = new CustomFormat(); /*inisialisasi model karyawan yang diisi dari model pelamar*/ $model->attributes = $modelp->getAttributes(); $model->nama_karyawan = $modelp->nama_pelamar; $model->tempatlahir_karyawan = $modelp->tempatlahir_pelamar; $model->tgllahir_karyawan = $modelp->tgl_lahirpelamar; $model->tglditerima = $modelp->tglditerima; $model->alamat_karyawan = $modelp->alamat_pelamar; $model->nomobile_karyawan = $modelp->nomobile_pelamar; $model->warganegara_karyawan = $modelp->warganegara_pelamar; $model->photo_karyawan = $modelp->photopelamar; $model->agama = $modelp->agama; $model->pelamar_id = $modelp->pelamar_id; if (isset($_POST['KKaryawanM'])) { $model->unsetAttributes(); $model->attributes = $_POST['KKaryawanM']; $model->tglditerima = $_POST['tglditerima']; //$format->formatDateForDb($_POST['tglditerima']); $model->karyawan_aktif = 1; $model->tgllahir_karyawan = $_POST['tgllahir_karyawan']; $model->create_user_id = Yii::app()->session['loginpemakai_id']; $model->create_time = date('Y-m-d H:i:s'); $modelp->tglditerima = $model->tglditerima; $modelp->tglmulaibekerja = isset($_POST['tglmulaibekerja']) ? $_POST['tglmulaibekerja'] : null; // $modelp->tgllowongan = $format->formatDbtoDate($modelp->tgllowongan); // $modelp->Create_Time = $format->formatDbToDateTime($modelp->Create_Time); // print_r($modelp->tgl_lahirpelamar);exit(); // $modelp->tgl_lahirpelamar = $format->formatDbtoDate($modelp->tgl_lahirpelamar); // print_r($modelp->tgl_lahirpelamar);exit(); $transaksi = Yii::app()->db->beginTransaction(); // try{ if (!empty($model->photo_karyawan)) { $model->photo_karyawan = $random . $model->photo_karyawan; Yii::import("ext.EPhpThumb.EPhpThumb"); $thumb = new EPhpThumb(); $thumb->init(); // this is needed $fullImgName = $model->photo_karyawan; $fullImgSource = Params::pathIconModulDirectory() . $fullImgName; $fullThumbSource = Params::pathIconModulThumbsDirectory() . 'kecil_' . $fullImgName; if ($model->validate()) { if ($model->save()) { $gambar->saveAs($fullImgSource); $thumb->create($fullImgSource)->resize(200, 200)->save($fullThumbSource); $modelp->karyawan_id = $model->karyawan_id; $modelp->save(); $transaksi->commit(); $this->redirect(array('admin')); } } } else { $model->photo_karyawan = $modelp->photopelamar; if ($model->validate()) { // print_r($model->attributes);exit(); if ($model->save()) { $modelp->karyawan_id = $model->karyawan_id; $modelp->save(); $transaksi->commit(); $this->redirect(array('admin')); } } } //}catch(Exception $e){ // $transaksi->rollback(); // } } $this->render('updatekaryawan', array('model' => $model, 'modelp' => $modelp)); }
public function actionUpdateTab1($id) { $model = $this->loadModel($id); $info = EmployeeInfo::model()->findByPk($model->employee_transaction_employee_id); $photo = EmployeePhotos::model()->findByPk($model->employee_transaction_emp_photos_id); $lang = LanguagesKnown::model()->findByPk($model->employee_transaction_languages_known_id); $this->performAjaxValidation(array($info, $model)); if (isset($_POST['EmployeeTransaction'])) { EmployeeTransaction::model()->updateByPk($id, array('employee_transaction_designation_id' => $_POST['EmployeeTransaction']['employee_transaction_designation_id'], 'employee_transaction_department_id' => $_POST['EmployeeTransaction']['employee_transaction_department_id'], 'employee_transaction_nationality_id' => $_POST['EmployeeTransaction']['employee_transaction_nationality_id'])); if ($_POST['EmployeeInfo']['employee_dob'] != "") { $dateofbirth = date("Y-m-d", strtotime($_POST['EmployeeInfo']['employee_dob'])); } else { $dateofbirth = NULL; } EmployeeInfo::model()->updateByPk($info->employee_id, array('employee_no' => $_POST['EmployeeInfo']['employee_no'], 'employee_name_alias' => $_POST['EmployeeInfo']['employee_name_alias'], 'employee_joining_date' => date("Y-m-d", strtotime($_POST['EmployeeInfo']['employee_joining_date'])), 'title' => $_POST['EmployeeInfo']['title'], 'employee_first_name' => $_POST['EmployeeInfo']['employee_first_name'], 'employee_last_name' => $_POST['EmployeeInfo']['employee_last_name'], 'employee_dob' => $dateofbirth, 'employee_gender' => $_POST['EmployeeInfo']['employee_gender'], 'employee_bloodgroup' => $_POST['EmployeeInfo']['employee_bloodgroup'], 'employee_marital_status' => $_POST['EmployeeInfo']['employee_marital_status'], 'employee_type' => $_POST['EmployeeInfo']['employee_type'], 'employee_private_mobile' => $_POST['EmployeeInfo']['employee_private_mobile'], 'employee_private_email' => $_POST['EmployeeInfo']['employee_private_email'], 'employee_faculty_of' => $_POST['EmployeeInfo']['employee_faculty_of'])); $lang->languages_known1 = $_POST['LanguagesKnown']['languages_known1']; $lang->save(); if (isset($_POST['EmployeePhotos'])) { $old_photo = $photo->employee_photos_path; $photo->employee_photos_path = CUploadedFile::getInstance($photo, 'employee_photos_path'); if ($photo->employee_photos_path == null) { $valid_photo = true; } else { $valid_photo = $photo->validate(); } if ($valid_photo) { if ($photo->employee_photos_path != null) { $newfname = ''; $ext = substr(strrchr($photo->employee_photos_path, '.'), 1); //following thing done for deleting previously uploaded photo $photo1 = $old_photo; $dir1 = Yii::getPathOfAlias('webroot') . '/college_data/emp_images/'; if (file_exists($dir1 . $photo1) && $photo1 != 'no-images') { unlink($dir1 . $photo1); } if ($ext != null) { $newfname = $info->employee_attendance_card_id . '.' . $ext; $photo->employee_photos_path->saveAs(Yii::getPathOfAlias('webroot') . '/college_data/emp_images/' . ($photo->employee_photos_path = $newfname)); } Yii::import("ext.EPhpThumb.EPhpThumb"); $thumb = new EPhpThumb(); $thumb->init(); //this is needed $thumb->create(Yii::getPathOfAlias('webroot') . '/college_data/emp_images/' . ($photo->employee_photos_path = $newfname))->resize(500, 500)->save(Yii::getPathOfAlias('webroot') . '/college_data/emp_images/' . $photo->employee_photos_path); $photo->save(false); } } } $this->redirect(array('update', 'id' => $id)); } $this->render('updateproftab1', array('model' => $model, 'info' => $info, 'photo' => $photo, 'lang' => $lang)); }