public function set_columns($columns) { if (function_exists('hook_filter_var') && $this->table_id) { $columns = hook_filter_var('table_columns', $columns, $this->table_id); } $this->columns = $columns; }
public static function email_invoice_to_customer($invoice_id, $debug = false) { // this is a copy of some of the code in invoie_admin_email.php // used in the CRON job when sending out automated emails. $invoice = module_invoice::get_invoice($invoice_id); // template for sending emails. // are we sending the paid one? or the dueone. $template_name = ''; $template_prefix = isset($invoice['invoice_template_email']) && strlen($invoice['invoice_template_email']) ? $invoice['invoice_template_email'] : 'invoice_email'; if (isset($invoice['credit_note_id']) && $invoice['credit_note_id']) { $template_name = 'credit_note_email'; } else { if ($invoice['date_paid'] && $invoice['date_paid'] != '0000-00-00') { $template_name = $template_prefix . '_paid'; } else { if ($invoice['overdue'] && $invoice['date_sent'] && $invoice['date_sent'] != '0000-00-00') { $template_name = $template_prefix . '_overdue'; } else { $template_name = $template_prefix . '_due'; } } } $template_name = hook_filter_var('invoice_email_template', $template_name, $invoice_id, $invoice); if (class_exists('module_company', false) && isset($invoice_data['company_id']) && (int) $invoice_data['company_id'] > 0) { module_company::set_current_company_id($invoice_data['company_id']); } $template = module_template::get_template_by_key($template_name); if (!$template || $template->template_key != $template_name) { // backup default templates incase someone has chosen a template that doesn't exist (eg: created invoice_email_MINE_due but not invoice_email_MINE_paid ) $template_prefix = 'invoice_email'; if ($invoice['date_paid'] && $invoice['date_paid'] != '0000-00-00') { $template_name = $template_prefix . '_paid'; } else { if ($invoice['overdue'] && $invoice['date_sent'] && $invoice['date_sent'] != '0000-00-00') { $template_name = $template_prefix . '_overdue'; } else { $template_name = $template_prefix . '_due'; } } } $replace = module_invoice::get_replace_fields($invoice_id, $invoice); if (defined('_BLOCK_EMAILS') && _BLOCK_EMAILS) { $pdf = false; } else { $pdf = module_invoice::generate_pdf($invoice_id); } $send_email_to = array(); $to = array(); if ($invoice['customer_id']) { $customer = module_customer::get_customer($invoice['customer_id']); $replace['customer_name'] = $customer['customer_name']; if ($invoice['user_id']) { // this invoice has a manually assigned user, only send the invoice to this user. // todo: should we also send to accounts? not sure - see if peopel complain $primary = module_user::get_user($invoice['user_id']); if ($primary) { $send_email_to[] = $primary; } } else { $to = module_user::get_contacts(array('customer_id' => $invoice['customer_id'])); // hunt for 'accounts' extra field $field_to_find = strtolower(module_config::c('accounts_extra_field_name', 'Accounts')); foreach ($to as $contact) { $extras = module_extra::get_extras(array('owner_table' => 'user', 'owner_id' => $contact['user_id'])); foreach ($extras as $e) { if (strtolower($e['extra_key']) == $field_to_find) { // this is the accounts contact - woo! $send_email_to[] = $contact; } } } if (!count($send_email_to) && $customer['primary_user_id']) { $primary = module_user::get_user($customer['primary_user_id']); if ($primary) { $send_email_to[] = $primary; } } } } else { if ($invoice['member_id']) { $member = module_member::get_member($invoice['member_id']); $to = array($member); $replace['customer_name'] = $member['first_name']; } else { $to = array(); } } $template->assign_values($replace); $html = $template->render('html'); // send an email to this user. $email = module_email::new_email(); $email->replace_values = $replace; // todo: send to all customer contacts ? if ($send_email_to) { foreach ($send_email_to as $send_email_t) { if (!empty($send_email_t['user_id'])) { $email->set_to('user', $send_email_t['user_id']); } else { if (!empty($send_email_t['email'])) { $email->set_to_manual($send_email_t['email']); } } } } else { foreach ($to as $t) { if (!empty($t['user_id'])) { $email->set_to('user', $t['user_id']); } else { if (!empty($t['email'])) { $email->set_to_manual($t['email']); } } break; // only 1? todo: all? } } $email->set_bcc_manual(module_config::c('admin_email_address', ''), ''); //$email->set_from('user',); // nfi $email->set_subject($template->description); // do we send images inline? $email->set_html($html); if ($pdf) { $email->add_attachment($pdf); } $email->invoice_id = $invoice_id; $email->customer_id = $invoice['customer_id']; $email->prevent_duplicates = true; if ($email->send($debug)) { // it worked successfully!! // record a log on the invoice when it's done. self::email_sent(array('invoice_id' => $invoice_id, 'template_name' => $template_name)); return true; } else { /// log err? return false; } }
$user = module_user::get_user(module_security::get_loggedin_id()); _e('Welcome %s', htmlspecialchars($user['name'])); ?> </h5> <ul class="list-unstyled user-info"> <li><small><i class="fa fa-user"></i> <a href="<?php echo module_user::link_open($_SESSION['_user_id']); ?> "><?php _e('Edit Profile'); ?> </a></small></li> <?php $header_buttons = array(); if (module_security::is_logged_in()) { $header_buttons = hook_filter_var('header_buttons', $header_buttons); } foreach ($header_buttons as $header_button) { ?> <li> <small><i class="fa fa-<?php echo $header_button['fa-icon']; ?> "></i> <a href="#" id="<?php echo $header_button['id']; ?> "> <?php echo $header_button['title'];
public static function display_extras($options) { $owner_id = isset($options['owner_id']) && $options['owner_id'] ? (int) $options['owner_id'] : false; $owner_table = isset($options['owner_table']) && $options['owner_table'] ? $options['owner_table'] : false; $layout = isset($options['layout']) && $options['layout'] ? $options['layout'] : false; $allow_new = true; if (isset($options['allow_new']) && !$options['allow_new']) { $allow_new = false; } $allow_edit = !isset($options['allow_edit']) || isset($options['allow_edit']) && $options['allow_edit']; if (!module_security::is_page_editable()) { $allow_edit = false; } // todo ^^ flow this permission check through to the "save" section. $html = ''; if ($owner_table) { $default_fields = self::get_defaults($owner_table); // we have all that we need to display some extras!! yey!! if ($owner_id) { $extra_items = self::get_extras(array('owner_table' => $owner_table, 'owner_id' => $owner_id)); $extra_items = self::sort_extras($extra_items, $default_fields); } else { $extra_items = array(); } foreach ($extra_items as $extra_item) { $extra_id = $extra_item['extra_id']; $id = 'extra_' . preg_replace('#\\W+#', '_', $extra_item['extra_key']); ob_start(); ?> <tr id="extra_<?php echo $extra_id; ?> "> <th <?php if (module_config::can_i('edit', 'Settings') && self::can_i('edit', 'Extra Fields') && isset($default_fields[$extra_item['extra_key']]['field_type'])) { echo ' data-settings-url="' . module_extra::link_open_extra_default($default_fields[$extra_item['extra_key']]['extra_default_id'], false) . '"'; } ?> > <?php if ($allow_edit) { ?> <span class="extra_field_key" onclick="$(this).hide(); $(this).parent().find('input').show();"><?php echo htmlspecialchars($extra_item['extra_key']); ?> </span> <input type="text" name="extra_<?php echo $owner_table; ?> _field[<?php echo $extra_id; ?> ][key]" value="<?php echo htmlspecialchars($extra_item['extra_key']); ?> " class="extra_field" style="display:none;"> <?php } else { echo htmlspecialchars($extra_item['extra_key']); ?> <input type="hidden" name="extra_<?php echo $owner_table; ?> _field[<?php echo $extra_id; ?> ][key]" value="<?php echo htmlspecialchars($extra_item['extra_key']); ?> "> <?php } ?> </th> <td> <?php if ($allow_edit) { $field_type = 'text'; if (isset($default_fields[$extra_item['extra_key']]['field_type'])) { $field_type = $default_fields[$extra_item['extra_key']]['field_type']; } if (!$field_type) { $field_type = 'text'; } $form_element = array('type' => $field_type, 'name' => 'extra_' . $owner_table . '_field[' . $extra_id . '][val]', 'value' => $extra_item['extra'], 'class' => 'extra_value_input', 'id' => $id); if ($field_type == 'select') { $form_element['options'] = array(); if (isset($default_fields[$extra_item['extra_key']]['options']) && is_array($default_fields[$extra_item['extra_key']]['options']) && isset($default_fields[$extra_item['extra_key']]['options']['select'])) { foreach (explode("\n", $default_fields[$extra_item['extra_key']]['options']['select']) as $val) { $val = trim($val); if ($val === '') { continue; } $form_element['options'][$val] = $val; } } } module_form::generate_form_element($form_element); } else { echo nl2br($extra_item['extra']); } /* <input type="text" name="extra_<?php echo $owner_table;?>_field[<?php echo $extra_id;?>][val]" id="<?php echo $id;?>" class="extra_value_input" value="<?php echo htmlspecialchars($extra_item['extra']);?>"> */ ?> </td> </tr> <?php $html .= ob_get_clean(); } if (module_security::is_page_editable() && $allow_new) { $extra_id = 'new'; ob_start(); // check if there are any "more" fields to add $more_fields_available = $allow_new; //if(!$more_fields_available){ foreach ($default_fields as $default_id => $default) { // check this key islany already existing. foreach ($extra_items as $extra_item) { if ($extra_item['extra_key'] == $default['key']) { unset($default_fields[$default_id]); continue 2; } } $more_fields_available = true; } //} if ($more_fields_available) { ?> <tr id="extra_<?php echo $owner_table; ?> _options_<?php echo $extra_id; ?> " <?php if (!module_config::c('hide_extra', 1)) { ?> style="display:none;"<?php } ?> > <th> </th> <td> <a href="#" onclick="$('#extra_<?php echo $owner_table; ?> _options_<?php echo $extra_id; ?> ').hide();$('#extra_<?php echo $owner_table; ?> _holder_<?php echo $extra_id; ?> ').show(); return false;"><?php _e('more fields »'); ?> </a> </td> </tr> <?php } // more fields available ?> <?php if (count($default_fields) || $allow_new) { ?> <tbody id="extra_<?php echo $owner_table; ?> _holder_<?php echo $extra_id; ?> " <?php if (module_config::c('hide_extra', 1)) { ?> style="display:none;"<?php } ?> > <!-- show all other options here from this $owner_table --> <?php $defaultid = 0; foreach ($default_fields as $default) { $defaultid++; $id = 'extra_' . preg_replace('#\\W+#', '_', $default['key']); ?> <tr> <th> <?php if ($allow_edit) { ?> <span class="extra_field_key" onclick="$(this).hide(); $(this).parent().find('input').show();"><?php echo htmlspecialchars($default['key']); ?> </span> <input type="text" name="extra_<?php echo $owner_table; ?> _field[new<?php echo $defaultid; ?> ][key]" value="<?php echo htmlspecialchars($default['key']); ?> " class="extra_field" style="display:none;"> <?php } else { echo htmlspecialchars($default['key']); ?> <input type="hidden" name="extra_<?php echo $owner_table; ?> _field[new<?php echo $defaultid; ?> ][key]" value="<?php echo htmlspecialchars($default['key']); ?> "> <?php } ?> </th> <td> <?php $field_type = $default['field_type']; if (!$field_type) { $field_type = 'text'; } $form_element = array('type' => $field_type, 'name' => 'extra_' . $owner_table . '_field[new' . $defaultid . '][val]', 'value' => '', 'class' => 'extra_value_input', 'id' => $id); if ($field_type == 'select') { $form_element['options'] = array(); if (isset($default['options']) && is_array($default['options']) && isset($default['options']['select'])) { foreach (explode("\n", $default['options']['select']) as $val) { $val = trim($val); if ($val === '') { continue; } $form_element['options'][$val] = $val; } } } module_form::generate_form_element($form_element); /*<input type="text" name="extra_<?php echo $owner_table;?>_field[new<?php echo $defaultid;?>][val]" id="<?php echo $id;?>" value="<?php ?>">*/ ?> </td> </tr> <?php } ?> <?php if ($allow_new) { ?> <tr id="extra_<?php echo $extra_id; ?> "> <th> <input type="text" name="extra_<?php echo $owner_table; ?> _field[<?php echo $extra_id; ?> ][key]" value="<?php ?> " class="extra_field"> </th> <td> <input type="text" name="extra_<?php echo $owner_table; ?> _field[<?php echo $extra_id; ?> ][val]" value="<?php ?> "> <?php _h('Enter anything you like in this blank field. eg: Passwords, Links, Notes, etc..'); ?> </td> </tr> <?php } ?> </tbody> <?php } // defaults / allow new $html .= ob_get_clean(); } // is page editable } // pass it out for a hook // this is really only used in the security module. if (function_exists('hook_filter_var')) { $html = hook_filter_var('extra_fields_output', $html, $owner_table, $owner_id); } else { $result = hook_handle_callback('extra_fields_output', $html, $owner_table, $owner_id); if ($result && count($result)) { foreach ($result as $r) { $html = $r; // bad. handle multiple hooks. } } } print $html; }
$template_prefix = isset($invoice['invoice_template_email']) && strlen($invoice['invoice_template_email']) ? $invoice['invoice_template_email'] : 'invoice_email'; if (isset($invoice['credit_note_id']) && $invoice['credit_note_id']) { $original_template_name = $template_name = 'credit_note_email'; } else { if ($invoice['date_paid'] && $invoice['date_paid'] != '0000-00-00') { $original_template_name = $template_name = $template_prefix . '_paid'; } else { if ($invoice['overdue'] && $invoice['date_sent'] && $invoice['date_sent'] != '0000-00-00') { $original_template_name = $template_name = $template_prefix . '_overdue'; } else { $original_template_name = $template_name = $template_prefix . '_due'; } } } $template_name = isset($_REQUEST['template_name']) ? $_REQUEST['template_name'] : $template_name; $template_name = hook_filter_var('invoice_email_template', $template_name, $invoice_id, $invoice); $template = module_template::get_template_by_key($template_name); $replace = module_invoice::get_replace_fields($invoice_id, $invoice); $replace['from_name'] = module_security::get_loggedin_name(); // generate the PDF ready for sending. $pdf = module_invoice::generate_pdf($invoice_id); // find available "to" recipients. // customer contacts. $to_select = false; $to = array(); if ($invoice['customer_id']) { $customer = module_customer::get_customer($invoice['customer_id']); $replace['customer_name'] = $customer['customer_name']; if ($invoice['user_id']) { $primary = module_user::get_user($invoice['user_id']); if ($primary) {
function get_form_element($element, $viewing_revision = false, $data_record = array()) { $has_write_access = !$viewing_revision; // convert our data field to an element. $element['name'] = isset($element['name']) && !empty($element['name']) ? $element['name'] : 'data_field[' . $element['data_field_id'] . ']'; $element['id'] = 'data_field_' . $element['data_field_id'] . ''; $element['type'] = $element['field_type']; if (!isset($element['value'])) { $element['value'] = ''; } if (!$has_write_access) { //$element['disabled'] = 'disabled'; $element['class'] = 'data_field_view'; } $highlight = false; $this->ajax_edit = false; $input_name = $element['name']; if (!$input_name) { return false; } if (isset($element['id']) && $element['id']) { $input_id = $element['id']; } else { $element['id'] = $input_name; $input_id = $input_name; } //if(!$value && isset($_REQUEST[$input_name]))$value = $_REQUEST[$input_name]; if (!$element['value']) { $element['value'] = $element['default']; } if (!is_array($element['value'])) { //$value=htmlspecialchars($value); } if (!isset($element['class'])) { $element['class'] = ''; } $attr = $attr_other = ''; if ($has_write_access) { if ($element['type'] == 'radio' || $element['type'] == 'checkbox_list') { // hacky! if ($element['required']) { $attr_other .= ' class="form_field form_field_required"'; } else { $attr_other .= ' class="form_field"'; } } else { $element['class'] .= " form_field"; if ($element['required']) { $element['class'] .= " form_field_required"; } } switch ($element['type']) { case 'date': $element['class'] .= " date_field"; if (!isset($element['size']) || !$element['size']) { $element['size'] = 8; } if (strtolower($element['value']) == 'now') { $element['value'] = print_date(time()); } break; case 'datetime': $element['class'] .= " date_time_field"; if (!isset($element['size']) || !$element['size']) { $element['size'] = 12; } if (strtolower($element['value']) == 'now') { $element['value'] = print_date(time(), true); } break; } } switch ($element['type']) { case 'checkbox_list': case 'radio': $element['attributes'] = array(); foreach (explode("\n", trim($element['field_data'])) as $line) { $line = trim($line); if (preg_match('/^attributes=/', $line)) { $line = preg_replace('/^attributes=/', '', $line); $element['attributes'] = explode("|", $line); break; } } break; case 'select': if (!isset($element['attributes']) || !is_array($element['attributes']) || !count($element['attributes'])) { $element['attributes'] = array(); foreach (explode("\n", trim($element['field_data'])) as $line) { $line = trim($line); if (preg_match('/^attributes=/', $line)) { $line = preg_replace('/^attributes=/', '', $line); if (preg_match('#hook:([\\w_]+)$#', $line, $matches)) { // see if we get anything back from this hook. $attributes = array(); $attributes = hook_filter_var($matches[1], $attributes, $element); if (is_array($attributes)) { $element['attributes'] = $attributes; } else { $element['attributes'] = array('Unable to call hook: ' . $matches[1]); } } else { $element['attributes'] = explode("|", $line); } break; } } } break; } if (!isset($element['style'])) { $element['style'] = ''; } // we have to apply some custom width/height styles if they exist. $width = $height = false; foreach (explode("\n", trim($element['field_data'])) as $line) { $line = trim($line); if (preg_match('/^width=/', $line)) { $line = preg_replace('/^width=/', '', $line); $width = (int) $line; } if (preg_match('/^height=/', $line)) { $line = preg_replace('/^height=/', '', $line); $height = (int) $line; } } if (!$height && $height < _MIN_INPUT_HEIGHT) { $height = _MIN_INPUT_HEIGHT; } switch ($element['type']) { case 'text': case 'date': case 'datetime': if ($width) { $element['style'] .= 'width:' . $width . 'px; '; } break; case 'radio': if ($width) { $attr_other .= ' style="width:' . $width . 'px; "'; } break; case 'textarea': case 'textbox': if ($width) { $element['style'] .= 'width:' . $width . 'px; '; } if ($has_write_access && $height) { $element['style'] .= 'height:' . $height . 'px; '; } break; } if (isset($element['width'])) { unset($element['width']); } if (isset($element['height'])) { unset($element['height']); } if (isset($element['multiple']) && $element['multiple']) { $element['multiple'] = true; // pass 'multiple' through to the UCM form builder which should handle everything $value_unserialize = @unserialize($element['value']); if (is_array($value_unserialize)) { $element['values'] = $value_unserialize; // 'values' is used in the UCM field generation tool } $element['name'] = $element['name'] . '[]'; } else { $element['multiple'] = false; } if (!$has_write_access && $element['multiple'] && isset($element['values']) && is_array($element['values'])) { $element['value'] = $element['values']; } if (is_array($element['value']) && count($element['value'])) { $all_values = $element['value']; } else { $all_values = array($element['value']); } if ($element['type'] == 'checkbox_list') { $test = @unserialize($element['value']); if (is_array($test) && count($test)) { $all_values = array($test); } else { $all_values = array($element['value']); } } if ($element['type'] == "cancel" && !isset($element['onclick'])) { $element['onclick'] = "history.go(-1);"; } if ($highlight) { $element['class'] .= " form_field_highlight"; } /*if(!$has_write_access){ $element['class'] .= ' form_disabled'; }*/ $attribute_keys = array('class', 'disabled', 'onclick', 'onfocus', 'onmouseup', 'onmousedown', 'onchange', 'size', 'cols', 'rows', 'width', 'style'); foreach ($element as $key => $val) { if (!is_array($val) && !trim($val)) { continue; } if (in_array(strtolower($key), $attribute_keys)) { if (in_array(strtolower($key), array('size', 'cols', 'rows', 'width', 'height')) && (int) $val == 0) { continue; } $attr .= ' ' . $key . '="' . $val . '"'; } } // check for default values, these are cleared when submitting the form if ($element['default']) { $has_default = true; } $real_input_id = $input_id; $real_input_name = $input_name; ob_start(); foreach ($all_values as $value_key => $value) { if (!$has_write_access) { // disabled. if (isset($width) && $width && $element['type'] != 'encrypted') { echo '<span ' . $attr; echo ' style="width:' . $width . 'px;"'; echo '> '; } // display value differently depending on value type. switch ($element['type']) { case 'checkbox_list': $other = ''; if (is_array($value)) { if (isset($value['other_val'])) { $other = $value['other_val']; unset($value['other_val']); } echo implode(', ', array_keys($value)); } echo ' ' . $other; break; case 'select': if (isset($element['attributes'])) { $attributes = $element['attributes']; } else { $attributes = array(); } if (isset($attributes[0])) { $new_attributes = array(); foreach ($attributes as $aid => $a) { $new_attributes[$aid + 1] = $a; } $attributes = $new_attributes; } if (isset($attributes[$value])) { echo $attributes[$value]; } break; case 'textarea': case 'textbox': echo nl2br(htmlspecialchars($value)); break; case 'file': if ($value) { $file_data = @unserialize($value); $file_link = 'includes/plugin_data/upload/' . $file_data['file']; if (is_file($file_link)) { $download_link = self::link_public_file_download($data_record['data_record_id'], $data_record['data_type_id'], $element['data_field_group_id'], $element['data_field_id']); echo '<a href="' . $download_link . '" target="_blank">' . $file_data['name'] . '</a>'; } else { echo 'File Not Found'; } } break; case 'wysiwyg': echo module_security::purify_html($value); break; case 'encrypted': if (class_exists('module_encrypt', false)) { ob_start(); $element['type'] = 'text'; module_form::generate_form_element($element); $enc_html = ob_get_clean(); echo module_encrypt::parse_html_input('custom_data', $enc_html, false); } break; case 'created_date_time': echo isset($data_record['date_created']) && $data_record['date_created'] != '0000-00-00 00:00:00' ? print_date($data_record['date_created'], true) : _l('N/A'); break; case 'created_date': echo isset($data_record['date_created']) && $data_record['date_created'] != '0000-00-00 00:00:00' ? print_date($data_record['date_created'], false) : _l('N/A'); break; case 'created_time': echo isset($data_record['date_created']) && $data_record['date_created'] != '0000-00-00 00:00:00' ? date(module_config::c('time_format', 'g:ia'), strtotime($data_record['date_created'])) : _l('N/A'); break; case 'updated_date_time': echo isset($data_record['date_updated']) && $data_record['date_updated'] != '0000-00-00 00:00:00' ? print_date($data_record['date_updated'], true) : (isset($data_record['date_created']) && $data_record['date_created'] != '0000-00-00 00:00:00' ? print_date($data_record['date_created'], true) : _l('N/A')); break; case 'updated_date': echo isset($data_record['date_updated']) && $data_record['date_updated'] != '0000-00-00 00:00:00' ? print_date($data_record['date_updated'], false) : (isset($data_record['date_created']) && $data_record['date_created'] != '0000-00-00 00:00:00' ? print_date($data_record['date_created'], false) : _l('N/A')); break; case 'updated_time': echo isset($data_record['date_updated']) && $data_record['date_updated'] != '0000-00-00 00:00:00' ? date(module_config::c('time_format', 'g:ia'), strtotime($data_record['date_updated'])) : (isset($data_record['date_created']) && $data_record['date_created'] != '0000-00-00 00:00:00' ? date(module_config::c('time_format', 'g:ia'), strtotime($data_record['date_created'])) : _l('N/A')); break; case 'created_by': echo isset($data_record['create_user_id']) && (int) $data_record['create_user_id'] > 0 ? module_user::link_open($data_record['create_user_id'], true) : _l('N/A'); break; case 'updated_by': echo isset($data_record['update_user_id']) && (int) $data_record['update_user_id'] > 0 ? module_user::link_open($data_record['update_user_id'], true) : (isset($data_record['create_user_id']) && (int) $data_record['create_user_id'] > 0 ? module_user::link_open($data_record['create_user_id'], true) : _l('N/A')); break; case 'url': echo '<a href="' . htmlspecialchars($value) . '" target="_blank">' . htmlspecialchars($value) . '</a>'; break; default: echo htmlspecialchars($value); break; } if (isset($width) && $width && $element['type'] != 'encrypted') { echo ' </span>'; } } else { // update for UCM: use the ucm form generator if (isset($element['default']) && $element['default'] && !$element['value']) { $element['value'] = $element['default']; } switch ($element['type']) { case 'wysiwyg': $element['options']['inline'] = false; module_form::generate_form_element($element); break; case "radio": $has_val = false; foreach ($element['attributes'] as $attribute) { $this_input_id = $input_id . preg_replace('/[^a-zA-Z]/', '', $attribute); ?> <span class="field_radio"> <input type="radio" name="<?php echo $input_name; ?> " id="<?php echo $this_input_id; ?> " value="<?php echo htmlspecialchars($attribute); ?> "<?php if ($attribute == $value || strtolower($attribute) == 'other' && !$has_val) { // assumes "OTHER" is always last... fix with a separate loop before hand checking all vals if (strtolower($attribute) != 'other') { $has_val = true; } echo " checked"; } echo ' ' . $attr; if (strtolower($attribute) == 'other') { echo ' onmouseup="if(this.checked)$(\'#other_' . $this_input_id . '\')[0].focus();"'; echo ' onchange="if(this.checked)$(\'#other_' . $this_input_id . '\')[0].focus();"'; } ?> > <label for="<?php echo $this_input_id; ?> "><?php echo $attribute; ?> </label> <?php if (strtolower($attribute) == 'other') { ?> <span class="data_field_input"> <input type="text" name="other_<?php echo $input_name; ?> " id="other_<?php echo $this_input_id; ?> " value="<?php if (!$has_val) { echo htmlspecialchars($value); } ?> " onchange="$('input[type=radio]',$(this).parent())[0].checked = true;" <?php echo $attr . $attr_other; ?> > </span> <?php } ?> </span> <?php } break; case "checkbox_list": $has_val = false; if (!is_array($value)) { $value = array(); } foreach ($element['attributes'] as $attribute) { $this_input_id = $input_id . preg_replace('/[^a-zA-Z]/', '', $attribute); ?> <span class="field_radio"> <input type="checkbox" name="<?php echo $input_name; ?> [<?php echo htmlspecialchars($attribute); ?> ]" id="<?php echo $this_input_id; ?> " value="1"<?php if (isset($value[$attribute])) { if (strtolower($attribute) != 'other') { $has_val = true; } echo " checked"; } echo ' ' . $attr; if (strtolower($attribute) == 'other') { echo ' onmouseup="if(this.checked)$(\'#other_' . $this_input_id . '\')[0].focus();"'; echo ' onchange="if(this.checked)$(\'#other_' . $this_input_id . '\')[0].focus();"'; } ?> > <label for="<?php echo $this_input_id; ?> "><?php echo $attribute; ?> </label> <?php if (strtolower($attribute) == 'other') { ?> <span class="data_field_input"> <input type="text" name="<?php echo $input_name; ?> [other_val]" id="other_<?php echo $this_input_id; ?> " value="<?php echo isset($value['other_val']) ? htmlspecialchars($value['other_val']) : ''; ?> " onchange="$('input[type=radio]',$(this).parent())[0].checked = true;" <?php echo $attr . $attr_other; ?> > </span> <?php } ?> </span> <?php } break; case "file": $this->has_files = true; ?> <input type="file" name="<?php echo $input_name; ?> " id="<?php echo $input_id; ?> " value="<?php echo $value; ?> "<?php echo $attr; ?> > <?php break; case 'select': $attributes = isset($element['attributes']) ? $element['attributes'] : array(); if (isset($attributes[0])) { $new_attributes = array(); foreach ($attributes as $aid => $a) { $new_attributes[$aid + 1] = $a; } $attributes = $new_attributes; } $element['options'] = $attributes; module_form::generate_form_element($element); break; case 'encrypted': if (class_exists('module_encrypt', false)) { ob_start(); $element['type'] = 'text'; module_form::generate_form_element($element); $enc_html = ob_get_clean(); echo module_encrypt::parse_html_input('custom_data', $enc_html); } break; case 'created_date_time': echo isset($data_record['date_created']) && $data_record['date_created'] != '0000-00-00 00:00:00' ? print_date($data_record['date_created'], true) : _l('N/A'); break; case 'created_date': echo isset($data_record['date_created']) && $data_record['date_created'] != '0000-00-00 00:00:00' ? print_date($data_record['date_created'], false) : _l('N/A'); break; case 'created_time': echo isset($data_record['date_created']) && $data_record['date_created'] != '0000-00-00 00:00:00' ? date(module_config::c('time_format', 'g:ia'), strtotime($data_record['date_created'])) : _l('N/A'); break; case 'updated_date_time': echo isset($data_record['date_updated']) && $data_record['date_updated'] != '0000-00-00 00:00:00' ? print_date($data_record['date_updated'], true) : (isset($data_record['date_created']) && $data_record['date_created'] != '0000-00-00 00:00:00' ? print_date($data_record['date_created'], true) : _l('N/A')); break; case 'updated_date': echo isset($data_record['date_updated']) && $data_record['date_updated'] != '0000-00-00 00:00:00' ? print_date($data_record['date_updated'], false) : (isset($data_record['date_created']) && $data_record['date_created'] != '0000-00-00 00:00:00' ? print_date($data_record['date_created'], false) : _l('N/A')); break; case 'updated_time': echo isset($data_record['date_updated']) && $data_record['date_updated'] != '0000-00-00 00:00:00' ? date(module_config::c('time_format', 'g:ia'), strtotime($data_record['date_updated'])) : (isset($data_record['date_created']) && $data_record['date_created'] != '0000-00-00 00:00:00' ? date(module_config::c('time_format', 'g:ia'), strtotime($data_record['date_created'])) : _l('N/A')); break; case 'created_by': echo isset($data_record['create_user_id']) && (int) $data_record['create_user_id'] > 0 ? module_user::link_open($data_record['create_user_id'], true) : _l('N/A'); break; case 'updated_by': echo isset($data_record['update_user_id']) && (int) $data_record['update_user_id'] > 0 ? module_user::link_open($data_record['update_user_id'], true) : (isset($data_record['create_user_id']) && (int) $data_record['create_user_id'] > 0 ? module_user::link_open($data_record['create_user_id'], true) : _l('N/A')); break; case 'url': $element['type'] = 'text'; module_form::generate_form_element($element); break; default: module_form::generate_form_element($element); } if (isset($element['after_link']) && $element['after_link']) { if (preg_match('/^https?:\\/\\//', $value) || ($have_www = preg_match('/^www\\./', $value) || ($have_www = preg_match('/\\.com/', $value) && !preg_match('/\\w@\\w/', $value)))) { // we have a url if ($have_www) { $value = "http://" . $value; } ?> <a href="<?php echo $value; ?> " target="_blank">»</a> <?php } if (preg_match('/\\w@\\w/', $value)) { ?> <a href="mailto:<?php echo $value; ?> ">»</a> <?php } } } // editable echo ' '; } // foreach all values //${$element_id} = ob_get_clean(); // we just print the html for now return ob_get_clean(); }
public static function get_quote($quote_id, $full = true, $skip_permissions = false) { $quote_id = (int) $quote_id; if ($quote_id <= 0) { $quote = array(); } else { $cache_key = self::_quote_cache_key($quote_id, array($quote_id, $full, $skip_permissions)); if ($cached_item = module_cache::get('quote', $cache_key)) { if (function_exists('hook_filter_var')) { $cached_item = hook_filter_var('get_quote', $cached_item, $quote_id); } return $cached_item; } $cache_key_full = self::_quote_cache_key($quote_id, array($quote_id, true, $skip_permissions)); if ($cache_key_full != $cache_key && ($cached_item = module_cache::get('quote', $cache_key_full))) { if (function_exists('hook_filter_var')) { $cached_item = hook_filter_var('get_quote', $cached_item, $quote_id); } return $cached_item; } $cache_timeout = module_config::c('cache_objects', 60); $quote = get_single("quote", "quote_id", $quote_id); } // check permissions if ($quote && isset($quote['quote_id']) && $quote['quote_id'] == $quote_id) { switch (self::get_quote_access_permissions()) { case _QUOTE_ACCESS_ALL: break; case _QUOTE_ACCESS_ASSIGNED: // only assigned quotes! $has_quote_access = false; if ($quote['user_id'] == module_security::get_loggedin_id()) { $has_quote_access = true; break; } $tasks = module_quote::get_tasks($quote['quote_id']); foreach ($tasks as $task) { if ($task['user_id'] == module_security::get_loggedin_id()) { $has_quote_access = true; break; } } unset($tasks); if (!$has_quote_access) { if ($skip_permissions) { $quote['_no_access'] = true; // set a flag for custom processing. we check for this when calling get_customer with the skip permissions argument. (eg: in the ticket file listing link) } else { $quote = false; } } break; case _QUOTE_ACCESS_CUSTOMER: // tie in with customer permissions to only get quotes from customers we can access. $customers = module_customer::get_customers(); $has_quote_access = false; if (isset($customers[$quote['customer_id']])) { $has_quote_access = true; } /*foreach($customers as $customer){ // todo, if($quote['customer_id'] == 0) // ignore this permission if($customer['customer_id']==$quote['customer_id']){ $has_quote_access = true; break; } }*/ unset($customers); if (!$has_quote_access) { if ($skip_permissions) { $quote['_no_access'] = true; // set a flag for custom processing. we check for this when calling get_customer with the skip permissions argument. (eg: in the ticket file listing link) } else { $quote = false; } } break; } if (!$quote) { $quote = array(); if (function_exists('hook_filter_var')) { $quote = hook_filter_var('get_quote', $quote, $quote_id); } return $quote; } $quote['taxes'] = get_multiple('quote_tax', array('quote_id' => $quote_id), 'quote_tax_id', 'exact', 'order'); } if (!$full) { if (isset($cache_key)) { module_cache::put('quote', $cache_key, $quote, $cache_timeout); } if (function_exists('hook_filter_var')) { $quote = hook_filter_var('get_quote', $quote, $quote_id); } return $quote; } if (!$quote) { $customer_id = 0; if (isset($_REQUEST['customer_id']) && $_REQUEST['customer_id']) { // $customer_id = (int) $_REQUEST['customer_id']; // find default website id to use. if (isset($_REQUEST['website_id'])) { $website_id = (int) $_REQUEST['website_id']; } else { } } $default_quote_name = module_config::c('quote_default_new_name', ''); if (module_config::c('quote_name_incrementing', 0)) { $quote_number = module_config::c('quote_name_incrementing_next', 1); // see if there is an quote number matching this one. $this_quote_number = $quote_number; do { $quotes = get_multiple('quote', array('name' => $this_quote_number)); //'customer_id'=>$customer_id, if (!count($quotes)) { $quote_number = $this_quote_number; } else { $this_quote_number++; } } while (count($quotes)); module_config::save_config('quote_name_incrementing_next', $quote_number); $default_quote_name = $quote_number . $default_quote_name; } $quote = array('quote_id' => 'new', 'customer_id' => $customer_id, 'website_id' => isset($_REQUEST['website_id']) ? $_REQUEST['website_id'] : 0, 'hourly_rate' => module_config::c('hourly_rate', 60), 'name' => $default_quote_name, 'date_create' => date('Y-m-d'), 'date_approved' => '0000-00-00', 'approved_by' => '', 'user_id' => module_security::get_loggedin_id(), 'contact_user_id' => -1, 'status' => module_config::s('quote_status_default', 'New'), 'tax_type' => module_config::c('invoice_tax_type', 0), 'type' => module_config::s('quote_type_default', 'Website Design'), 'currency_id' => module_config::c('default_currency_id', 1), 'auto_task_numbers' => '0', 'default_task_type' => module_config::c('default_task_type', _TASK_TYPE_HOURS_AMOUNT), 'description' => '', 'discount_description' => _l('Discount:'), 'discount_amount' => 0, 'discount_type' => module_config::c('invoice_discount_type', _DISCOUNT_TYPE_BEFORE_TAX)); // some defaults from the db. $quote['total_tax_rate'] = module_config::c('tax_percent', 10); $quote['total_tax_name'] = module_config::c('tax_name', 'TAX'); if ($customer_id > 0) { $customer_data = module_customer::get_customer($customer_id, false, true); if ($customer_data && isset($customer_data['default_tax']) && $customer_data['default_tax'] >= 0) { $quote['total_tax_rate'] = $customer_data['default_tax']; $quote['total_tax_name'] = $customer_data['default_tax_name']; } } } // new support for multiple taxes if (!isset($quote['taxes']) || !count($quote['taxes']) && $quote['total_tax_rate'] > 0) { $quote['taxes'] = array(); $tax_rates = explode(',', $quote['total_tax_rate']); $tax_names = explode(',', $quote['total_tax_name']); foreach ($tax_rates as $tax_rate_id => $tax_rate_amount) { if ($tax_rate_amount > 0) { $quote['taxes'][] = array('order' => 0, 'percent' => $tax_rate_amount, 'name' => isset($tax_names[$tax_rate_id]) ? $tax_names[$tax_rate_id] : $quote['total_tax_name'], 'total' => 0, 'amount' => 0, 'discount' => 0, 'increment' => module_config::c('tax_multiple_increment', 0)); } } } if ($quote) { // work out total hours etc.. $quote['total_hours'] = 0; $quote['total_hours_completed'] = 0; $quote['total_hours_overworked'] = 0; $quote['total_sub_amount'] = 0; $quote['total_sub_amount_taxable'] = 0; $quote['total_sub_amount_unbillable'] = 0; $quote['total_sub_amount_invoicable'] = 0; $quote['total_sub_amount_invoicable_taxable'] = 0; $quote['total_amount_invoicable'] = 0; $quote['total_tasks_remain'] = 0; $quote['total_amount'] = 0; $quote['total_amount_paid'] = 0; $quote['total_amount_invoiced'] = 0; $quote['total_amount_invoiced_deposit'] = 0; $quote['total_amount_todo'] = 0; $quote['total_amount_outstanding'] = 0; $quote['total_amount_due'] = 0; $quote['total_hours_remain'] = 0; $quote['total_percent_complete'] = 0; $quote['total_tax'] = 0; $quote['total_tax_invoicable'] = 0; // $quote['invoice_discount_amount'] = 0; // $quote['invoice_discount_amount_on_tax'] = 0; // $quote['total_amount_discounted'] = 0; // new feature to invoice incompleted tasks $quote['uninvoiced_quote_task_ids'] = array(); $quote_items = self::get_quote_items((int) $quote['quote_id'], $quote); foreach ($quote_items as $quote_item) { if ($quote_item['quote_item_amount'] != 0) { // we have a custom amount for this quote_item if ($quote_item['billable']) { $quote['total_sub_amount'] += $quote_item['quote_item_amount']; if ($quote_item['taxable']) { $quote['total_sub_amount_taxable'] += $quote_item['quote_item_amount']; if (module_config::c('tax_calculate_mode', _TAX_CALCULATE_AT_END) == _TAX_CALCULATE_INCREMENTAL) { // tax calculated along the way (this isn't the recommended way, but was included as a feature request) // we add tax to each of the tax array items //$quote['total_tax'] += round(($quote_item['quote_item_amount'] * ($quote['total_tax_rate'] / 100)),module_config::c('currency_decimal_places',2)); foreach ($quote['taxes'] as $quote_tax_id => $quote_tax) { if (!isset($quote['taxes'][$quote_tax_id]['total'])) { $quote['taxes'][$quote_tax_id]['total'] = 0; } $quote['taxes'][$quote_tax_id]['total'] += $quote_item['quote_item_amount']; $quote['taxes'][$quote_tax_id]['amount'] += round($quote_item['quote_item_amount'] * ($quote_tax['percent'] / 100), module_config::c('currency_decimal_places', 2)); } } } } else { $quote['total_sub_amount_unbillable'] += $quote_item['quote_item_amount']; } } } // add any discounts. if ($quote['discount_amount'] != 0) { if ($quote['discount_type'] == _DISCOUNT_TYPE_AFTER_TAX) { // after tax discount :::::::::: // handled below. //$quote['final_modification'] = -$quote['discount_amount']; } else { if ($quote['discount_type'] == _DISCOUNT_TYPE_BEFORE_TAX) { // before tax discount::::: //$quote['final_modification'] = -$quote['discount_amount']; // problem : this 'discount_amount_on_tax' calculation may not match the correct final discount calculation as per below if (module_config::c('tax_calculate_mode', _TAX_CALCULATE_AT_END) == _TAX_CALCULATE_INCREMENTAL) { // tax calculated along the way. // we have discounted the 'total amount taxable' so that means we need to reduce the tax amount by that much as well. foreach ($quote['taxes'] as $quote_tax_id => $quote_tax) { $this_tax_discount = round($quote['discount_amount'] * ($quote['taxes'][$quote_tax_id]['percent'] / 100), module_config::c('currency_decimal_places', 2)); $quote['discount_amount_on_tax'] += $this_tax_discount; if (!isset($quote['taxes'][$quote_tax_id]['total'])) { $quote['taxes'][$quote_tax_id]['total'] = 0; } $quote['taxes'][$quote_tax_id]['total'] -= $quote['discount_amount']; $quote['taxes'][$quote_tax_id]['amount'] -= $this_tax_discount; $quote['taxes'][$quote_tax_id]['discount'] = $this_tax_discount; } } else { // we work out what the tax would have been if there was no applied discount // this is used in job.php $quote['taxes_backup'] = $quote['taxes']; $quote['total_sub_amount_taxable_backup'] = $quote['total_sub_amount_taxable']; $total_tax_before_discount = 0; foreach ($quote['taxes'] as $quote_tax_id => $quote_tax) { $quote['taxes'][$quote_tax_id]['total'] = $quote['total_sub_amount_taxable']; $quote['taxes'][$quote_tax_id]['amount'] = round($quote['total_sub_amount_taxable'] * ($quote_tax['percent'] / 100), module_config::c('currency_decimal_places', 2)); // here we adjust the 'total_sub_amount_taxable' to include the value from the previous calculation. // this is for multiple taxes that addup as they go (eg: Canada) if (isset($quote_tax['increment']) && $quote_tax['increment']) { $quote['total_sub_amount_taxable'] += $quote['taxes'][$quote_tax_id]['amount']; } $total_tax_before_discount += $quote['taxes'][$quote_tax_id]['amount']; } $quote['taxes'] = $quote['taxes_backup']; $quote['total_sub_amount_taxable'] = $quote['total_sub_amount_taxable_backup']; } $quote['total_sub_amount'] -= $quote['discount_amount']; $quote['total_sub_amount_taxable'] -= $quote['discount_amount']; } } } if (module_config::c('tax_calculate_mode', _TAX_CALCULATE_AT_END) == _TAX_CALCULATE_AT_END) { // tax needs to be calculated based on the total_sub_amount_taxable $previous_quote_tax_id = false; foreach ($quote['taxes'] as $quote_tax_id => $quote_tax) { $quote['taxes'][$quote_tax_id]['total'] = $quote['total_sub_amount_taxable']; if (isset($quote_tax['increment']) && $quote_tax['increment'] && $previous_quote_tax_id) { $quote['taxes'][$quote_tax_id]['total'] += $quote['taxes'][$previous_quote_tax_id]['amount']; } $quote['taxes'][$quote_tax_id]['amount'] = round($quote['taxes'][$quote_tax_id]['total'] * ($quote_tax['percent'] / 100), module_config::c('currency_decimal_places', 2)); // here we adjust the 'total_sub_amount_taxable' to include the value from the previous calculation. // this is for multiple taxes that addup as they go (eg: Canada) $previous_quote_tax_id = $quote_tax_id; } //$quote['total_tax'] = round(($quote['total_sub_amount_taxable'] * ($quote['total_tax_rate'] / 100)),module_config::c('currency_decimal_places',2)); } else { //$quote['total_tax'] = 0; } if (isset($quote['tax_type']) && $quote['tax_type'] == 1) { // hack! not completely correct, oh well. // todo - make this work with more than 1 tax rate. // $amount / 1.05 ( this is 1 + tax %) // this will only work if a single tax has been included. if (is_array($quote['taxes']) && count($quote['taxes']) > 1) { set_error('Included tax calculation only works with 1 tax rate'); } else { if (is_array($quote['taxes']) && count($quote['taxes'])) { reset($quote['taxes']); $quote_tax_id = key($quote['taxes']); if (isset($quote['taxes'][$quote_tax_id])) { $taxable_amount = $quote['total_sub_amount_taxable'] / (1 + $quote['taxes'][$quote_tax_id]['percent'] / 100); $quote['taxes'][$quote_tax_id]['amount'] = $quote['total_sub_amount_taxable'] - $taxable_amount; $quote['total_sub_amount'] = $quote['total_sub_amount'] - $quote['taxes'][$quote_tax_id]['amount']; } } } } $quote['total_tax'] = 0; foreach ($quote['taxes'] as $quote_tax_id => $quote_tax) { $quote['total_tax'] += $quote_tax['amount']; } $quote['total_amount'] = $quote['total_sub_amount'] + $quote['total_tax']; if ($quote['discount_type'] == _DISCOUNT_TYPE_AFTER_TAX) { $quote['total_amount'] -= $quote['discount_amount']; } $quote['total_amount'] = round($quote['total_amount'], module_config::c('currency_decimal_places', 2)); } if (isset($cache_key)) { module_cache::put('quote', $cache_key, $quote, $cache_timeout); } if (function_exists('hook_filter_var')) { $quote = hook_filter_var('get_quote', $quote, $quote_id); } return $quote; }
function metris_generate_fieldset($callback, $options) { $defaults = array('id' => false, 'type' => 'table', 'title' => false, 'title_type' => 'h5', 'heading' => false, 'row_title_class' => 'width1', 'row_data_class' => '', 'elements' => array(), 'class' => 'tableclass tableclass_form', 'extra_settings' => array(), 'elements_before' => '', 'elements_after' => ''); $options = array_merge($defaults, $options); if (function_exists('hook_filter_var')) { $options = hook_filter_var('generate_fieldset_options', $options); } ob_start(); ?> <div class="box <?php echo isset($options['heading']['responsive']) ? ' box-responsive' : ''; ?> "> <header> <?php if ($options['heading']) { if (!isset($options['heading']['type']) || $options['heading']['type'] != 'h5') { $options['heading']['type'] = 'h5'; } print_heading($options['heading']); } else { if ($options['title']) { ?> <<?php echo $options['title_type']; ?> ><?php _e($options['title']); ?> </<?php echo $options['title_type']; ?> > <?php } } ?> </header> <!-- .block --> <div class="body"> <?php echo $options['elements_before']; ?> <?php if ($options['elements']) { ?> <table class="<?php echo $options['class']; ?> "> <tbody> <?php foreach ($options['elements'] as $element) { if (isset($element['ignore']) && $element['ignore']) { continue; } if (isset($element['field']) && !isset($element['fields'])) { $element['fields'] = array($element['field']); unset($element['field']); } ?> <tr> <?php if (isset($element['message']) && $element['message'] || isset($element['warning']) && isset($element['warning'])) { ?> <th colspan="2" style="text-align:center"> <?php if (isset($element['message'])) { ?> <?php echo $element['message']; ?> <?php } else { if (isset($element['warning'])) { ?> <span class="error_text"><?php echo $element['warning']; ?> </span> <?php } } ?> </th> <?php } else { ?> <?php if (isset($element['title'])) { ?> <th class="<?php echo isset($element['row_title_class']) ? $element['row_title_class'] : $options['row_title_class']; ?> "> <?php echo htmlspecialchars(_l($element['title'])); ?> </th> <?php } if (isset($element['fields'])) { ?> <td class="<?php echo isset($element['row_data_class']) ? $element['row_data_class'] : $options['row_data_class']; ?> "> <?php if (is_array($element['fields'])) { foreach ($element['fields'] as $dataid => $field) { if (is_array($field)) { // treat this as a call to the form generate option module_form::generate_form_element($field); echo ' '; } else { if (is_closure($field)) { $field(); } else { echo $field . ' '; } } } } else { echo $element['fields']; } ?> </td> <?php } ?> </tr> <?php } } if (class_exists('module_extra') && module_extra::is_plugin_enabled() && $options['extra_settings']) { module_extra::display_extras($options['extra_settings']); } ?> </tbody> </table> <?php } echo $options['elements_after']; ?> </div> <!-- /.block --> </div> <?php return ob_get_clean(); }
public static function generate_fieldset($options) { // let the themes override this search bar function. $result = hook_handle_callback('generate_fieldset', $options); if (is_array($result)) { // has been handed by a theme. return current($result); } $defaults = array('id' => false, 'type' => 'table', 'title' => false, 'title_type' => 'h3', 'heading' => false, 'row_title_class' => 'width1', 'row_data_class' => '', 'elements' => array(), 'class' => 'tableclass tableclass_form', 'extra_settings' => array(), 'elements_before' => '', 'elements_after' => ''); $options = array_merge($defaults, $options); if (function_exists('hook_filter_var')) { $options = hook_filter_var('generate_fieldset_options', $options); } //todo - hook in here for themes. ob_start(); if ($options['heading']) { print_heading($options['heading']); } else { if ($options['title']) { ?> <<?php echo $options['title_type']; ?> ><?php _e($options['title']); ?> </<?php echo $options['title_type']; ?> > <?php } } ?> <?php echo $options['elements_before']; ?> <?php if ($options['elements']) { ?> <table class="<?php echo $options['class']; ?> "> <tbody> <?php foreach ($options['elements'] as $element) { if (isset($element['ignore']) && $element['ignore']) { continue; } if (isset($element['field']) && !isset($element['fields'])) { $element['fields'] = array($element['field']); unset($element['field']); } ?> <tr> <?php if (isset($element['message']) && $element['message'] || isset($element['warning']) && isset($element['warning'])) { ?> <td colspan="2" align="center"> <?php if (isset($element['message'])) { ?> <?php echo $element['message']; ?> <?php } else { if (isset($element['warning'])) { ?> <span class="error_text"><?php echo $element['warning']; ?> </span> <?php } } ?> </td> <?php } else { ?> <?php if (isset($element['title'])) { ?> <th class="<?php echo isset($element['row_title_class']) ? $element['row_title_class'] : $options['row_title_class']; ?> "> <?php echo htmlspecialchars(_l($element['title'])); ?> </th> <?php } if (isset($element['fields'])) { ?> <td class="<?php echo isset($element['row_data_class']) ? $element['row_data_class'] : $options['row_data_class']; ?> "> <?php if (is_array($element['fields'])) { foreach ($element['fields'] as $dataid => $field) { if (is_array($field)) { // treat this as a call to the form generate option self::generate_form_element($field); echo ' '; } else { if (is_closure($field)) { $field(); } else { echo $field . ' '; } } } } else { echo $element['fields']; } ?> </td> <?php } ?> </tr> <?php } } if (class_exists('module_extra') && module_extra::is_plugin_enabled() && $options['extra_settings']) { module_extra::display_extras($options['extra_settings']); } ?> </tbody> </table> <?php } echo $options['elements_after']; ?> <?php return ob_get_clean(); }
function adminlte_generate_fieldset($callback, $options) { $defaults = array('id' => false, 'type' => 'table', 'title' => false, 'title_type' => 'h3', 'heading' => false, 'row_title_class' => 'width1', 'row_data_class' => '', 'elements' => array(), 'class' => 'tableclass tableclass_form', 'extra_settings' => array(), 'elements_before' => '', 'elements_after' => ''); $options = array_merge($defaults, $options); if (function_exists('hook_filter_var')) { $options = hook_filter_var('generate_fieldset_options', $options); } ob_start(); ?> <div class="box <?php echo module_theme::get_config('adminlte_boxstyle', 'box-solid'); echo isset($options['heading']['responsive']) ? ' box-responsive' : ''; ?> "> <div class="box-header"> <?php if ($options['heading']) { if (!isset($options['heading']['type']) || $options['heading']['type'] != 'h3') { $options['heading']['type'] = 'h3'; } $options['heading']['class'] = 'box-title'; print_heading($options['heading']); } else { if ($options['title']) { ?> <<?php echo $options['title_type']; ?> class="box-title"><?php _e($options['title']); ?> </<?php echo $options['title_type']; ?> > <?php } } ?> </div> <!-- .block --> <div class="box-body"> <?php echo $options['elements_before']; ?> <?php if ($options['elements']) { if (module_theme::get_config('adminlte_formstyle', 'table') == 'table') { ?> <table class="<?php echo $options['class']; ?> "> <tbody> <?php foreach ($options['elements'] as $element) { if (isset($element['ignore']) && $element['ignore']) { continue; } if (isset($element['field']) && !isset($element['fields'])) { $element['fields'] = array($element['field']); unset($element['field']); } ?> <tr> <?php if (isset($element['message']) && $element['message'] || isset($element['warning']) && isset($element['warning'])) { ?> <th colspan="2" class="text-center"> <?php if (isset($element['message'])) { ?> <?php echo $element['message']; ?> <?php } else { if (isset($element['warning'])) { ?> <span class="error_text"><?php echo $element['warning']; ?> </span> <?php } } ?> </th> <?php } else { ?> <th class="<?php echo isset($element['row_title_class']) ? $element['row_title_class'] : $options['row_title_class']; ?> "> <?php if (isset($element['title'])) { ?> <?php echo htmlspecialchars(_l($element['title'])); ?> <?php } ?> </th> <td class="<?php echo isset($element['row_data_class']) ? $element['row_data_class'] : $options['row_data_class']; ?> "> <?php if (isset($element['fields'])) { ?> <?php if (is_array($element['fields'])) { foreach ($element['fields'] as $dataid => $field) { if (is_array($field)) { // treat this as a call to the form generate option module_form::generate_form_element($field); echo ' '; } else { if (is_closure($field)) { $field(); } else { echo $field . ' '; } } } } else { echo $element['fields']; } ?> <?php } // fields ?> </td> <!-- /.input-group --> <?php } //else ?> </tr> <!-- /.form-group --> <?php } if (class_exists('module_extra') && module_extra::is_plugin_enabled() && $options['extra_settings']) { module_extra::display_extras($options['extra_settings']); } ?> </tbody> </table> <!-- /.elements --> <?php // end table layout } else { if (module_theme::get_config('adminlte_formstyle', 'table') == 'div') { ?> <div class="<?php echo $options['class']; ?> "> <?php foreach ($options['elements'] as $element) { if (isset($element['ignore']) && $element['ignore']) { continue; } if (isset($element['field']) && !isset($element['fields'])) { $element['fields'] = array($element['field']); unset($element['field']); } ?> <div class="form-group"> <?php if (isset($element['message']) && $element['message'] || isset($element['warning']) && isset($element['warning'])) { ?> <div class="text-center"> <?php if (isset($element['message'])) { ?> <?php echo $element['message']; ?> <?php } else { if (isset($element['warning'])) { ?> <span class="error_text"><?php echo $element['warning']; ?> </span> <?php } } ?> </div> <?php } else { ?> <div class="input-group<?php echo !isset($element['title']) ? '-notitle' : ''; ?> "> <?php if (isset($element['title'])) { ?> <span class="input-group-addon table-row-title"><span class="<?php echo isset($element['row_title_class']) ? $element['row_title_class'] : $options['row_title_class']; ?> "><?php echo htmlspecialchars(_l($element['title'])); ?> </span></span> <?php } if (isset($element['fields'])) { ?> <?php if (is_array($element['fields'])) { // if there is only one element we put it up in the form-control so that it displays nicely. // if there are more than one elements we wrap them in a div form-control. $do_wrap = true; if (count($element['fields']) == 1) { $field = current($element['fields']); if (is_array($field) && $field['type'] != 'wysiwyg' && $field['type'] != 'check' && $field['type'] != 'checkbox') { $do_wrap = false; $currency = false; if ($field['type'] == 'currency') { $field['type'] = 'text'; $currency = true; //$field['class'] = (isset($field['class']) ? $field['class'] : '') .' currency '; } $field['class'] = (isset($field['class']) ? $field['class'] : '') . ' form-control ' . (isset($element['row_data_class']) ? $element['row_data_class'] : $options['row_data_class']); $help_text = false; if (isset($field['help'])) { // we put the help element outside in its own <span class="input-group-addon"></span> // don't let the generatE_form_element produce it. $help_text = $field['help']; unset($field['help']); } module_form::generate_form_element($field); if ($currency) { ?> <span class="input-group-addon"><?php echo currency('', true, isset($field['currency_id']) ? $field['currency_id'] : false); ?> </span> <?php } if ($help_text) { ?> <span class="input-group-addon"><?php _h($help_text); ?> </span> <?php } } } if ($do_wrap) { ?> <div class="form-control<?php echo !isset($element['title']) ? '-notitle' : ''; ?> <?php echo isset($element['row_data_class']) ? $element['row_data_class'] : $options['row_data_class']; ?> "> <?php $help_text = false; foreach ($element['fields'] as $dataid => $field) { if (is_array($field) && isset($field['help'])) { // this element has a help text. if ($help_text) { // already a help text (shouldn't happen, ditch it.. and display multiple as normal) $help_text = false; break; } else { $help_text = $field['help']; } } } foreach ($element['fields'] as $dataid => $field) { if (is_array($field)) { if (isset($field['help']) && $help_text) { unset($field['help']); } // treat this as a call to the form generate option module_form::generate_form_element($field); echo ' '; } else { if (is_closure($field)) { $field(); } else { echo $field . ' '; } } } ?> </div> <?php if ($help_text) { ?> <span class="input-group-addon"><?php _h($help_text); ?> </span> <?php } } } else { ?> <div class="form-control <?php echo isset($element['row_data_class']) ? $element['row_data_class'] : $options['row_data_class']; ?> "> <?php echo $element['fields']; ?> </div> <?php } ?> <?php } // fields ?> </div> <!-- /.input-group --> <?php } //else ?> </div> <!-- /.form-group --> <?php } if (class_exists('module_extra') && module_extra::is_plugin_enabled() && $options['extra_settings']) { module_extra::display_extras($options['extra_settings']); } ?> </div> <!-- /.elements --> <?php } else { if (module_theme::get_config('adminlte_formstyle', 'table') == 'long') { ?> <div class="<?php echo $options['class']; ?> "> <?php foreach ($options['elements'] as $element) { if (isset($element['ignore']) && $element['ignore']) { continue; } if (isset($element['field']) && !isset($element['fields'])) { $element['fields'] = array($element['field']); unset($element['field']); } ?> <div class="form-group form-group-long"> <?php if (isset($element['message']) && $element['message'] || isset($element['warning']) && isset($element['warning'])) { ?> <div class="text-center"> <?php if (isset($element['message'])) { ?> <?php echo $element['message']; ?> <?php } else { if (isset($element['warning'])) { ?> <span class="error_text"><?php echo $element['warning']; ?> </span> <?php } } ?> </div> <?php } else { ?> <?php if (isset($element['title'])) { ?> <label class="<?php echo isset($element['row_title_class']) ? $element['row_title_class'] : $options['row_title_class']; ?> "><?php echo htmlspecialchars(_l($element['title'])); ?> </label> <?php } if (isset($element['fields'])) { ?> <?php if (is_array($element['fields'])) { foreach ($element['fields'] as $dataid => $field) { if (is_array($field)) { // treat this as a call to the form generate option $field['class'] = (isset($field['class']) ? $field['class'] : '') . ' ' . (isset($element['row_data_class']) ? $element['row_data_class'] : $options['row_data_class']); switch ($field['type']) { case 'check': case 'checkbox': case 'wysiwyg': break; default: $field['class'] .= ' form-control '; } module_form::generate_form_element($field); echo ' '; } else { if (is_closure($field)) { $field(); } else { echo $field . ' '; } } } } else { ?> <div class="form-control <?php echo isset($element['row_data_class']) ? $element['row_data_class'] : $options['row_data_class']; ?> "> <?php echo $element['fields']; ?> </div> <?php } ?> <?php } // fields ?> <?php } //else ?> </div> <!-- /.form-group --> <?php } if (class_exists('module_extra') && module_extra::is_plugin_enabled() && $options['extra_settings']) { module_extra::display_extras($options['extra_settings']); } ?> </div> <!-- /.elements --> <?php } } } // end div layout } echo $options['elements_after']; ?> <!-- /.block --> </div> </div> <?php return ob_get_clean(); }