From af164930aa70b1309cda606f59a21f59cd87d528 Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Wed, 13 Jul 2016 15:38:37 +0200 Subject: [PATCH] Move crop image into formvalidator and the file class to avoid doubles --- main/admin/user_add.php | 71 ++---------------- main/admin/user_edit.php | 68 ++--------------- main/auth/profile.php | 63 +--------------- main/course_info/infocours.php | 74 ++----------------- main/inc/lib/extra_field.lib.php | 5 +- .../lib/formvalidator/FormValidator.class.php | 17 +++++ main/inc/lib/pear/HTML/QuickForm/file.php | 71 ++++++++++++++++++ main/inc/lib/sessionmanager.lib.php | 2 +- main/session/session_add.php | 66 +---------------- main/session/session_edit.php | 64 ---------------- 10 files changed, 113 insertions(+), 388 deletions(-) diff --git a/main/admin/user_add.php b/main/admin/user_add.php index 69abd9e450..805824781b 100755 --- a/main/admin/user_add.php +++ b/main/admin/user_add.php @@ -44,56 +44,6 @@ if ($checkPass == 'true') { } $htmlHeadXtra[] = ''; $htmlHeadXtra[] = ''; -$htmlHeadXtra[] = ''; - - $htmlHeadXtra[] = ' '; $htmlHeadXtra[] = ''; -$htmlHeadXtra[] = ''; $libpath = api_get_path(LIBRARY_PATH); $noPHP_SELF = true; @@ -332,24 +287,13 @@ if ($userGeolocalization) { } // Picture -$form->addElement('file', 'picture', get_lang('AddPicture'), array('id' => 'picture', 'class' => 'picture-form')); +$form->addFile( + 'picture', + get_lang('AddImage'), + array('id' => 'picture', 'class' => 'picture-form', 'crop_image' => true) +); $allowed_picture_types = array ('jpg', 'jpeg', 'png', 'gif'); -$form->addHtml('
- -
-
- -
-
- -
-
-
'); - -$form->addHidden('cropResult', ''); - $form->addRule( 'picture', get_lang('OnlyImagesAllowed').' ('.implode(',', $allowed_picture_types).')', @@ -617,7 +561,7 @@ if ($form->validate()) { $currentUserId = api_get_user_id(); $userObj = api_get_user_entity($user_id); - + UserManager::add_user_as_admin($userObj); if ($user_id != $currentUserId) { diff --git a/main/auth/profile.php b/main/auth/profile.php index 3d6005d42c..ebe958366a 100755 --- a/main/auth/profile.php +++ b/main/auth/profile.php @@ -38,48 +38,6 @@ $htmlHeadXtra[] = ''; $htmlHeadXtra[] = ''; -$htmlHeadXtra[] = ''; - $show_delete_watermark_text_message = false; if (api_get_setting('pdf_export_watermark_by_course') == 'true') { if (isset($_GET['delete_watermark'])) { @@ -193,24 +144,13 @@ $form->addText('department_url', get_lang('DepartmentUrl'), false); $form->applyFilter('department_url', 'html_filter'); // Picture -$form->addElement('file', 'picture', get_lang('AddPicture'), array('id' => 'picture', 'class' => 'picture-form')); -$form->addHtml(' -
- -
-
- -
-
- -
-
-
-'); -$form->addHidden('cropResult', ''); -$allowed_picture_types = array ('jpg', 'jpeg', 'png', 'gif'); +$form->addFile( + 'picture', + get_lang('AddPicture'), + array('id' => 'picture', 'class' => 'picture-form', 'crop_image' => true) +); + +$allowed_picture_types = array('jpg', 'jpeg', 'png', 'gif'); $form->addRule( 'picture', get_lang('OnlyImagesAllowed').' ('.implode(',', $allowed_picture_types).')', diff --git a/main/inc/lib/extra_field.lib.php b/main/inc/lib/extra_field.lib.php index f6f5db18cf..20baa9b162 100755 --- a/main/inc/lib/extra_field.lib.php +++ b/main/inc/lib/extra_field.lib.php @@ -1477,11 +1477,10 @@ EOF; $fieldTexts[0] = get_lang($fieldTexts[0]); } - $form->addElement( - 'file', + $form->addFile( $fieldVariable, $fieldTexts, - ['accept' => 'image/*', 'id' => 'extra_image'] + ['accept' => 'image/*', 'id' => 'extra_image', 'crop_image' => 'true'] ); $form->applyFilter('extra_'.$field_details['variable'], 'stripslashes'); diff --git a/main/inc/lib/formvalidator/FormValidator.class.php b/main/inc/lib/formvalidator/FormValidator.class.php index c5d9e8f390..c81c2d78d9 100755 --- a/main/inc/lib/formvalidator/FormValidator.class.php +++ b/main/inc/lib/formvalidator/FormValidator.class.php @@ -809,6 +809,23 @@ EOT; public function addFile($name, $label, $attributes = array()) { $this->addElement('file', $name, $label, $attributes); + if (isset($attributes['crop_image'])) { + $this->addHtml(' +
+ +
+
+ +
+
+ +
+
+
' + ); + $this->addHidden('cropResult', ''); + } } /** diff --git a/main/inc/lib/pear/HTML/QuickForm/file.php b/main/inc/lib/pear/HTML/QuickForm/file.php index 1d6c061518..65a738df8b 100755 --- a/main/inc/lib/pear/HTML/QuickForm/file.php +++ b/main/inc/lib/pear/HTML/QuickForm/file.php @@ -266,4 +266,75 @@ class HTML_QuickForm_file extends HTML_QuickForm_input return null; } } + + /** + * @return string + */ + public function getElementJS() + { + $id = $this->getAttribute('id'); + return ''; + } + + public function toHtml() + { + $js = ''; + if (isset($this->_attributes['crop_image'])) { + $js = $this->getElementJS(); + } + + if ($this->_flagFrozen) { + return $this->getFrozenHtml(); + } else { + return $js.$this->_getTabs() . '_getAttrString($this->_attributes) . ' />'; + } + } //end func toHtml + } \ No newline at end of file diff --git a/main/inc/lib/sessionmanager.lib.php b/main/inc/lib/sessionmanager.lib.php index e5120dbb94..1bbd60c587 100755 --- a/main/inc/lib/sessionmanager.lib.php +++ b/main/inc/lib/sessionmanager.lib.php @@ -6899,7 +6899,7 @@ class SessionManager $extra_field = new ExtraField('session'); $extra = $extra_field->addElements($form, $sessionId); - $form->addElement('html',''); + $form->addElement('html', ''); $js = $extra['jquery_ready_content']; diff --git a/main/session/session_add.php b/main/session/session_add.php index f941eb648c..2d590f3f68 100644 --- a/main/session/session_add.php +++ b/main/session/session_add.php @@ -25,57 +25,10 @@ $errorMsg = ''; // Crop picture plugin for session images $htmlHeadXtra[] = ''; $htmlHeadXtra[] = ''; -$htmlHeadXtra[] = ''; $interbreadcrumb[] = array( 'url' => 'session_list.php', - 'name' => get_lang('SessionList'), + 'name' => get_lang('SessionList') ); function search_coachs($needle) @@ -191,23 +144,6 @@ $(function() { }); '; // @todo add an html element -$form->addHtml(' -
- -
-
- -
-
- -
-
-
-'); -$form->addHidden('cropResult', ''); - $form->addButtonNext(get_lang('NextStep')); if (!$formSent) { diff --git a/main/session/session_edit.php b/main/session/session_edit.php index 750bccad13..47c6f16569 100644 --- a/main/session/session_edit.php +++ b/main/session/session_edit.php @@ -17,53 +17,6 @@ $formSent = 0; // Crop picture plugin for session images $htmlHeadXtra[] = ''; $htmlHeadXtra[] = ''; -$htmlHeadXtra[] = ''; // Database Table Definitions $tbl_user = Database::get_main_table(TABLE_MAIN_USER); @@ -171,23 +124,6 @@ $(function() { }); '; -$form->addHtml(' -
- -
-
- -
-
- -
-
-
-'); -$form->addHidden('cropResult', ''); - $form->addButtonUpdate(get_lang('ModifyThisSession')); $formDefaults = $sessionInfo;