| Conditions | 21 |
| Paths | 7680 |
| Total Lines | 138 |
| Code Lines | 96 |
| Lines | 0 |
| Ratio | 0 % |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 111 | function manage_form($default, $select_from_user_list = null, $sent_to = null) |
||
| 112 | { |
||
| 113 | $group_id = isset($_REQUEST['group_id']) ? intval($_REQUEST['group_id']) : null; |
||
| 114 | $message_id = isset($_GET['message_id']) ? intval($_GET['message_id']) : null; |
||
| 115 | $param_f = isset($_GET['f']) && $_GET['f'] == 'social' ? 'social' : null; |
||
| 116 | |||
| 117 | $form = new FormValidator('compose_message', null, api_get_self().'?f='.$param_f, null, array('enctype'=>'multipart/form-data')); |
||
| 118 | if (empty($group_id)) { |
||
| 119 | if (isset($select_from_user_list)) { |
||
| 120 | $form->addText( |
||
| 121 | 'id_text_name', |
||
| 122 | get_lang('SendMessageTo'), |
||
| 123 | true, |
||
| 124 | array( |
||
| 125 | 'id'=>'id_text_name', |
||
| 126 | 'onkeyup'=>'send_request_and_search()', |
||
| 127 | 'autocomplete'=>'off' |
||
| 128 | ) |
||
| 129 | ); |
||
| 130 | $form->addRule('id_text_name', get_lang('ThisFieldIsRequired'), 'required'); |
||
| 131 | $form->addElement('html','<div id="id_div_search" style="padding:0px" class="message-select-box" > </div>'); |
||
| 132 | $form->addElement('hidden','user_list', 0, array('id'=>'user_list')); |
||
| 133 | } else { |
||
| 134 | if (!empty($sent_to)) { |
||
| 135 | $form->addLabel(get_lang('SendMessageTo'), $sent_to); |
||
| 136 | } |
||
| 137 | if (empty($default['users'])) { |
||
| 138 | //fb select |
||
| 139 | $form->addElement( |
||
| 140 | 'select_ajax', |
||
| 141 | 'users', |
||
| 142 | get_lang('SendMessageTo'), |
||
| 143 | array(), |
||
| 144 | [ |
||
| 145 | 'multiple' => 'multiple', |
||
| 146 | 'url' => api_get_path(WEB_AJAX_PATH) . 'message.ajax.php?a=find_users' |
||
| 147 | ] |
||
| 148 | ); |
||
| 149 | } else { |
||
| 150 | $form->addElement('hidden','hidden_user',$default['users'][0],array('id'=>'hidden_user')); |
||
| 151 | } |
||
| 152 | } |
||
| 153 | } else { |
||
| 154 | $userGroup = new UserGroup(); |
||
| 155 | $group_info = $userGroup->get($group_id); |
||
| 156 | |||
| 157 | $form->addElement('label', get_lang('ToGroup'), api_xml_http_response_encode($group_info['name'])); |
||
| 158 | $form->addElement('hidden','group_id',$group_id); |
||
| 159 | $form->addElement('hidden','parent_id',$message_id); |
||
| 160 | } |
||
| 161 | |||
| 162 | $form->addText('title', get_lang('Subject'), true); |
||
| 163 | $form->addHtmlEditor( |
||
| 164 | 'content', |
||
| 165 | get_lang('Message'), |
||
| 166 | false, |
||
| 167 | false, |
||
| 168 | array('ToolbarSet' => 'Messages', 'Width' => '100%', 'Height' => '250') |
||
| 169 | ); |
||
| 170 | |||
| 171 | if (isset($_GET['re_id'])) { |
||
| 172 | $message_reply_info = MessageManager::get_message_by_id($_GET['re_id']); |
||
| 173 | $default['title'] = get_lang('MailSubjectReplyShort')." ".$message_reply_info['title']; |
||
| 174 | $form->addElement('hidden','re_id', intval($_GET['re_id'])); |
||
| 175 | $form->addElement('hidden','save_form','save_form'); |
||
| 176 | |||
| 177 | //adding reply mail |
||
| 178 | $user_reply_info = api_get_user_info($message_reply_info['user_sender_id']); |
||
| 179 | $default['content'] = '<p><br/></p>'.sprintf( |
||
| 180 | get_lang('XWroteY'), |
||
| 181 | $user_reply_info['complete_name'], |
||
| 182 | Security::filter_terms($message_reply_info['content']) |
||
| 183 | ); |
||
| 184 | } |
||
| 185 | |||
| 186 | if (empty($group_id)) { |
||
| 187 | |||
| 188 | $form->addElement('label', '', '<div id="filepaths" class="form-group"> |
||
| 189 | <div id="filepath_1"> |
||
| 190 | <label>'.get_lang('FilesAttachment').'</label> |
||
| 191 | <input type="file" name="attach_1"/> |
||
| 192 | <label>'.get_lang('Description').'</label> |
||
| 193 | <input id="file-descrtiption" type="text" name="legend[]" class="form-control"/> |
||
| 194 | </div> |
||
| 195 | </div>' |
||
| 196 | ); |
||
| 197 | |||
| 198 | $form->addElement('label', '', '<span id="link-more-attach"><a href="javascript://" onclick="return add_image_form()">'.get_lang('AddOneMoreFile').'</a></span> ('.sprintf(get_lang('MaximunFileSizeX'),format_file_size(api_get_setting('message_max_upload_filesize'))).')'); |
||
| 199 | } |
||
| 200 | |||
| 201 | $form->addButtonSend(get_lang('SendMessage'), 'compose'); |
||
| 202 | $form->setRequiredNote('<span class="form_required">*</span> <small>'.get_lang('ThisFieldIsRequired').'</small>'); |
||
| 203 | |||
| 204 | if (!empty($group_id) && !empty($message_id)) { |
||
| 205 | $message_info = MessageManager::get_message_by_id($message_id); |
||
| 206 | $default['title'] = get_lang('MailSubjectReplyShort')." ".$message_info['title']; |
||
| 207 | } |
||
| 208 | $form->setDefaults($default); |
||
| 209 | $html = ''; |
||
| 210 | if ($form->validate()) { |
||
| 211 | $check = Security::check_token('post'); |
||
| 212 | if ($check) { |
||
| 213 | $user_list = $default['users']; |
||
| 214 | $file_comments = $_POST['legend']; |
||
| 215 | $title = $default['title']; |
||
| 216 | $content = $default['content']; |
||
| 217 | $group_id = isset($default['group_id']) ? $default['group_id'] : null; |
||
| 218 | $parent_id = isset($default['parent_id']) ? $default['parent_id'] : null; |
||
| 219 | if (is_array($user_list) && count($user_list)> 0) { |
||
| 220 | //all is well, send the message |
||
| 221 | foreach ($user_list as $user) { |
||
| 222 | $res = MessageManager::send_message( |
||
| 223 | $user, |
||
| 224 | $title, |
||
| 225 | $content, |
||
| 226 | $_FILES, |
||
| 227 | $file_comments, |
||
| 228 | $group_id, |
||
| 229 | $parent_id |
||
| 230 | ); |
||
| 231 | if ($res) { |
||
| 232 | $html .= MessageManager::display_success_message($user); |
||
|
|
|||
| 233 | } |
||
| 234 | } |
||
| 235 | } else { |
||
| 236 | Display::display_error_message('ErrorSendingMessage'); |
||
| 237 | } |
||
| 238 | } |
||
| 239 | Security::clear_token(); |
||
| 240 | } else { |
||
| 241 | $token = Security::get_token(); |
||
| 242 | $form->addElement('hidden','sec_token'); |
||
| 243 | $form->setConstants(array('sec_token' => $token)); |
||
| 244 | $html .= $form->returnForm(); |
||
| 245 | } |
||
| 246 | |||
| 247 | return $html; |
||
| 248 | } |
||
| 249 | |||
| 377 |
This method has been deprecated.