@@ -1727,7 +1727,7 @@ discard block |
||
| 1727 | 1727 | $isSelected = false; |
| 1728 | 1728 | |
| 1729 | 1729 | if(empty($option_key)) { |
| 1730 | - continue; |
|
| 1730 | + continue; |
|
| 1731 | 1731 | } |
| 1732 | 1732 | |
| 1733 | 1733 | if(empty($option_value)) { |
@@ -3128,8 +3128,8 @@ discard block |
||
| 3128 | 3128 | } |
| 3129 | 3129 | |
| 3130 | 3130 | // If there are some bug ridden versions, we should include them here |
| 3131 | - // and check immediately for one of this versions |
|
| 3132 | - $bug_php_versions = array(); |
|
| 3131 | + // and check immediately for one of this versions |
|
| 3132 | + $bug_php_versions = array(); |
|
| 3133 | 3133 | foreach ($bug_php_versions as $v) { |
| 3134 | 3134 | if ( version_compare($sys_php_version, $v, '=') === true) { |
| 3135 | 3135 | return -1; |
@@ -115,8 +115,8 @@ discard block |
||
| 115 | 115 | 'd.m.Y' => '23.12.2010', |
| 116 | 116 | 'm.d.Y' => '12.23.2010', |
| 117 | 117 | ) : $dateFormats, |
| 118 | - 'dbconfig' => $dbconfig, // this must be set!! |
|
| 119 | - 'dbconfigoption' => $dbconfigoption, // this must be set!! |
|
| 118 | + 'dbconfig' => $dbconfig, // this must be set!! |
|
| 119 | + 'dbconfigoption' => $dbconfigoption, // this must be set!! |
|
| 120 | 120 | 'default_action' => empty($default_action) ? 'index' : $default_action, |
| 121 | 121 | 'default_charset' => empty($default_charset) ? 'UTF-8' : $default_charset, |
| 122 | 122 | 'default_currency_name' => empty($default_currency_name) ? 'US Dollar' : $default_currency_name, |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | 'display_inbound_email_buttons' => empty($display_inbound_email_buttons) ? false : $display_inbound_email_buttons, |
| 145 | 145 | 'history_max_viewed' => empty($history_max_viewed) ? 50 : $history_max_viewed, |
| 146 | 146 | 'host_name' => empty($host_name) ? 'localhost' : $host_name, |
| 147 | - 'import_dir' => $import_dir, // this must be set!! |
|
| 147 | + 'import_dir' => $import_dir, // this must be set!! |
|
| 148 | 148 | 'import_max_records_per_file' => 100, |
| 149 | 149 | 'import_max_records_total_limit' => '', |
| 150 | 150 | 'languages' => empty($languages) ? array('en_us' => 'English (US)') : $languages, |
@@ -164,21 +164,21 @@ discard block |
||
| 164 | 164 | ), |
| 165 | 165 | 'require_accounts' => empty($requireAccounts) ? true : $requireAccounts, |
| 166 | 166 | 'rss_cache_time' => empty($RSS_CACHE_TIME) ? '10800' : $RSS_CACHE_TIME, |
| 167 | - 'session_dir' => $session_dir, // this must be set!! |
|
| 168 | - 'site_url' => empty($site_URL) ? $site_url : $site_URL, // this must be set!! |
|
| 167 | + 'session_dir' => $session_dir, // this must be set!! |
|
| 168 | + 'site_url' => empty($site_URL) ? $site_url : $site_URL, // this must be set!! |
|
| 169 | 169 | 'showDetailData' => true, // if true, read-only ACL fields will still appear on EditViews as non-editable |
| 170 | 170 | 'showThemePicker' => true, |
| 171 | 171 | 'sugar_version' => empty($sugar_version) ? 'unknown' : $sugar_version, |
| 172 | 172 | 'time_formats' => empty($timeFormats) ? array( |
| 173 | 173 | 'H:i' => '23:00', 'h:ia' => '11:00 pm', 'h:iA' => '11:00PM', |
| 174 | - 'H.i' => '23.00', 'h.ia' => '11.00 pm', 'h.iA' => '11.00PM', ) : $timeFormats, |
|
| 175 | - 'tmp_dir' => $tmp_dir, // this must be set!! |
|
| 174 | + 'H.i' => '23.00', 'h.ia' => '11.00 pm', 'h.iA' => '11.00PM',) : $timeFormats, |
|
| 175 | + 'tmp_dir' => $tmp_dir, // this must be set!! |
|
| 176 | 176 | 'translation_string_prefix' => empty($translation_string_prefix) ? false : $translation_string_prefix, |
| 177 | 177 | 'unique_key' => empty($unique_key) ? md5(create_guid()) : $unique_key, |
| 178 | 178 | 'upload_badext' => empty($upload_badext) ? array( |
| 179 | 179 | 'php', 'php3', 'php4', 'php5', 'pl', 'cgi', 'py', |
| 180 | - 'asp', 'cfm', 'js', 'vbs', 'html', 'htm', ) : $upload_badext, |
|
| 181 | - 'upload_dir' => $upload_dir, // this must be set!! |
|
| 180 | + 'asp', 'cfm', 'js', 'vbs', 'html', 'htm',) : $upload_badext, |
|
| 181 | + 'upload_dir' => $upload_dir, // this must be set!! |
|
| 182 | 182 | 'upload_maxsize' => empty($upload_maxsize) ? 30000000 : $upload_maxsize, |
| 183 | 183 | 'import_max_execution_time' => empty($import_max_execution_time) ? 3600 : $import_max_execution_time, |
| 184 | 184 | 'lock_homepage' => false, |
@@ -244,7 +244,7 @@ discard block |
||
| 244 | 244 | 'date_formats' => array( |
| 245 | 245 | 'Y-m-d' => '2010-12-23', 'm-d-Y' => '12-23-2010', 'd-m-Y' => '23-12-2010', |
| 246 | 246 | 'Y/m/d' => '2010/12/23', 'm/d/Y' => '12/23/2010', 'd/m/Y' => '23/12/2010', |
| 247 | - 'Y.m.d' => '2010.12.23', 'd.m.Y' => '23.12.2010', 'm.d.Y' => '12.23.2010', ), |
|
| 247 | + 'Y.m.d' => '2010.12.23', 'd.m.Y' => '23.12.2010', 'm.d.Y' => '12.23.2010',), |
|
| 248 | 248 | 'name_formats' => array( |
| 249 | 249 | 's f l' => 's f l', 'f l' => 'f l', 's l' => 's l', 'l, s f' => 'l, s f', |
| 250 | 250 | 'l, f' => 'l, f', 's l, f' => 's l, f', 'l s f' => 'l s f', 'l f s' => 'l f s', |
@@ -253,7 +253,7 @@ discard block |
||
| 253 | 253 | 'persistent' => true, |
| 254 | 254 | 'autofree' => false, |
| 255 | 255 | 'debug' => 0, |
| 256 | - 'ssl' => false, ), |
|
| 256 | + 'ssl' => false,), |
|
| 257 | 257 | 'default_action' => 'index', |
| 258 | 258 | 'default_charset' => return_session_value_or_default('default_charset', |
| 259 | 259 | 'UTF-8'), |
@@ -316,12 +316,12 @@ discard block |
||
| 316 | 316 | 'sugarbeet' => true, |
| 317 | 317 | 'time_formats' => array( |
| 318 | 318 | 'H:i' => '23:00', 'h:ia' => '11:00pm', 'h:iA' => '11:00PM', 'h:i a' => '11:00 pm', 'h:i A' => '11:00 PM', |
| 319 | - 'H.i' => '23.00', 'h.ia' => '11.00pm', 'h.iA' => '11.00PM', 'h.i a' => '11.00 pm', 'h.i A' => '11.00 PM', ), |
|
| 319 | + 'H.i' => '23.00', 'h.ia' => '11.00pm', 'h.iA' => '11.00PM', 'h.i a' => '11.00 pm', 'h.i A' => '11.00 PM',), |
|
| 320 | 320 | 'tracker_max_display_length' => 15, |
| 321 | 321 | 'translation_string_prefix' => return_session_value_or_default('translation_string_prefix', false), |
| 322 | 322 | 'upload_badext' => array( |
| 323 | 323 | 'php', 'php3', 'php4', 'php5', 'pl', 'cgi', 'py', |
| 324 | - 'asp', 'cfm', 'js', 'vbs', 'html', 'htm', 'phtml', ), |
|
| 324 | + 'asp', 'cfm', 'js', 'vbs', 'html', 'htm', 'phtml',), |
|
| 325 | 325 | 'upload_maxsize' => 30000000, |
| 326 | 326 | 'import_max_execution_time' => 3600, |
| 327 | 327 | // 'use_php_code_json' => returnPhpJsonStatus(), |
@@ -438,7 +438,7 @@ discard block |
||
| 438 | 438 | { |
| 439 | 439 | global $sugar_config; |
| 440 | 440 | |
| 441 | - if (is_windows() || !isset($sugar_config)|| !isset($addUser) || ($addUser == '')) { |
|
| 441 | + if (is_windows() || !isset($sugar_config) || !isset($addUser) || ($addUser == '')) { |
|
| 442 | 442 | return; |
| 443 | 443 | } |
| 444 | 444 | if (!array_key_exists('cron', $sugar_config)) { |
@@ -1687,11 +1687,11 @@ discard block |
||
| 1687 | 1687 | |
| 1688 | 1688 | $response = '<OPTION value="'.$value.'"'; |
| 1689 | 1689 | |
| 1690 | - if($isSelected === true) { |
|
| 1691 | - $response .= ' ' . 'selected'; |
|
| 1690 | + if ($isSelected === true) { |
|
| 1691 | + $response .= ' '.'selected'; |
|
| 1692 | 1692 | } |
| 1693 | 1693 | |
| 1694 | - $response .= '>' . $app_strings[$app_strings_label] . '</OPTION>'; |
|
| 1694 | + $response .= '>'.$app_strings[$app_strings_label].'</OPTION>'; |
|
| 1695 | 1695 | |
| 1696 | 1696 | return $response; |
| 1697 | 1697 | } |
@@ -1702,8 +1702,8 @@ discard block |
||
| 1702 | 1702 | |
| 1703 | 1703 | $response = '<OPTION value="'.$value.'"'; |
| 1704 | 1704 | |
| 1705 | - if($isSelected === true) { |
|
| 1706 | - $response .= ' ' . 'selected'; |
|
| 1705 | + if ($isSelected === true) { |
|
| 1706 | + $response .= ' '.'selected'; |
|
| 1707 | 1707 | } |
| 1708 | 1708 | |
| 1709 | 1709 | $response .= '>'; |
@@ -1726,15 +1726,15 @@ discard block |
||
| 1726 | 1726 | { |
| 1727 | 1727 | $isSelected = false; |
| 1728 | 1728 | |
| 1729 | - if(empty($option_key)) { |
|
| 1729 | + if (empty($option_key)) { |
|
| 1730 | 1730 | continue; |
| 1731 | 1731 | } |
| 1732 | 1732 | |
| 1733 | - if(empty($option_value)) { |
|
| 1733 | + if (empty($option_value)) { |
|
| 1734 | 1734 | continue; |
| 1735 | 1735 | } |
| 1736 | 1736 | |
| 1737 | - if($option_key === $selected_key) |
|
| 1737 | + if ($option_key === $selected_key) |
|
| 1738 | 1738 | { |
| 1739 | 1739 | $isSelected = true; |
| 1740 | 1740 | } |
@@ -2455,9 +2455,9 @@ discard block |
||
| 2455 | 2455 | { |
| 2456 | 2456 | $current_theme = SugarThemeRegistry::current(); |
| 2457 | 2457 | $theme_directory = $current_theme->dirName; |
| 2458 | - if(strpos($relative_path, "themes".DIRECTORY_SEPARATOR.$theme_directory) === false) { |
|
| 2458 | + if (strpos($relative_path, "themes".DIRECTORY_SEPARATOR.$theme_directory) === false) { |
|
| 2459 | 2459 | $test_path = SUGAR_PATH.DIRECTORY_SEPARATOR."themes".DIRECTORY_SEPARATOR.$theme_directory.DIRECTORY_SEPARATOR.$relative_path; |
| 2460 | - if(file_exists($test_path)) { |
|
| 2460 | + if (file_exists($test_path)) { |
|
| 2461 | 2461 | $resource_name = "themes".DIRECTORY_SEPARATOR.$theme_directory.DIRECTORY_SEPARATOR.$relative_path; |
| 2462 | 2462 | } |
| 2463 | 2463 | } |
@@ -3116,14 +3116,14 @@ discard block |
||
| 3116 | 3116 | * 0 if version is between minimun and recomended PHP versions, |
| 3117 | 3117 | * -1 otherwise (less than minimum or buggy version) |
| 3118 | 3118 | */ |
| 3119 | -function check_php_version($sys_php_version = ''){ |
|
| 3120 | -if ($sys_php_version === ''){ |
|
| 3121 | - $sys_php_version = constant('PHP_VERSION') ; |
|
| 3119 | +function check_php_version($sys_php_version = '') { |
|
| 3120 | +if ($sys_php_version === '') { |
|
| 3121 | + $sys_php_version = constant('PHP_VERSION'); |
|
| 3122 | 3122 | } |
| 3123 | 3123 | |
| 3124 | 3124 | // versions below MIN_PHP_VERSION are not accepted, so return early. |
| 3125 | - if ( version_compare($sys_php_version, constant('SUITECRM_PHP_MIN_VERSION'), '<') === true) { |
|
| 3126 | - return - 1; |
|
| 3125 | + if (version_compare($sys_php_version, constant('SUITECRM_PHP_MIN_VERSION'), '<') === true) { |
|
| 3126 | + return -1; |
|
| 3127 | 3127 | |
| 3128 | 3128 | } |
| 3129 | 3129 | |
@@ -3131,7 +3131,7 @@ discard block |
||
| 3131 | 3131 | // and check immediately for one of this versions |
| 3132 | 3132 | $bug_php_versions = array(); |
| 3133 | 3133 | foreach ($bug_php_versions as $v) { |
| 3134 | - if ( version_compare($sys_php_version, $v, '=') === true) { |
|
| 3134 | + if (version_compare($sys_php_version, $v, '=') === true) { |
|
| 3135 | 3135 | return -1; |
| 3136 | 3136 | |
| 3137 | 3137 | } |
@@ -4407,7 +4407,7 @@ discard block |
||
| 4407 | 4407 | |
| 4408 | 4408 | function _getIcon($iconFileName) |
| 4409 | 4409 | { |
| 4410 | - if(file_exists(SugarThemeRegistry::current()->getImagePath().DIRECTORY_SEPARATOR.'icon_'.$iconFileName.'.svg')) { |
|
| 4410 | + if (file_exists(SugarThemeRegistry::current()->getImagePath().DIRECTORY_SEPARATOR.'icon_'.$iconFileName.'.svg')) { |
|
| 4411 | 4411 | $iconName = "icon_{$iconFileName}.svg"; |
| 4412 | 4412 | $iconFound = SugarThemeRegistry::current()->getImageURL($iconName, false); |
| 4413 | 4413 | } |
@@ -47,9 +47,9 @@ discard block |
||
| 47 | 47 | |
| 48 | 48 | global $current_language, $app_strings, $app_list_strings, $current_user, $beanFiles, $beanList; |
| 49 | 49 | |
| 50 | - $bean = BeanFactory::getBean($module,$id); |
|
| 50 | + $bean = BeanFactory::getBean($module, $id); |
|
| 51 | 51 | |
| 52 | - if(!checkAccess($bean)){ |
|
| 52 | + if (!checkAccess($bean)) { |
|
| 53 | 53 | return false; |
| 54 | 54 | } |
| 55 | 55 | |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | $mod_strings = return_module_language($current_language, $module); |
| 60 | 60 | |
| 61 | 61 | // set the filename for this control |
| 62 | - $file = create_cache_directory('include/InlineEditing/') . $module . $view . $alt_type . $fieldname . '.tpl'; |
|
| 62 | + $file = create_cache_directory('include/InlineEditing/').$module.$view.$alt_type.$fieldname.'.tpl'; |
|
| 63 | 63 | |
| 64 | 64 | if (!is_file($file) |
| 65 | 65 | || inDeveloperMode() |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | if ($vardef['type'] == 'link') { |
| 105 | 105 | $vardef['type'] = 'relate'; |
| 106 | 106 | $vardef['rname'] = 'name'; |
| 107 | - $vardef['id_name'] = $vardef['name'] . '_id'; |
|
| 107 | + $vardef['id_name'] = $vardef['name'].'_id'; |
|
| 108 | 108 | if ((!isset($vardef['module']) || $vardef['module'] == '') && $focus->load_relationship($vardef['name'])) { |
| 109 | 109 | $vardef['module'] = $focus->{$vardef['name']}->getRelatedModuleName(); |
| 110 | 110 | } |
@@ -140,15 +140,15 @@ discard block |
||
| 140 | 140 | // Remove all the copyright comments |
| 141 | 141 | $contents = preg_replace('/\{\*[^\}]*?\*\}/', '', $contents); |
| 142 | 142 | // remove extra wrong javascript which breaks auto complete on flexi relationship parent fields |
| 143 | - $contents = preg_replace("/<script language=\"javascript\">if\(typeof sqs_objects == \'undefined\'\){var sqs_objects = new Array;}sqs_objects\[\'EditView_parent_name\'\].*?<\/script>/","",$contents); |
|
| 143 | + $contents = preg_replace("/<script language=\"javascript\">if\(typeof sqs_objects == \'undefined\'\){var sqs_objects = new Array;}sqs_objects\[\'EditView_parent_name\'\].*?<\/script>/", "", $contents); |
|
| 144 | 144 | |
| 145 | 145 | |
| 146 | 146 | if ($view == 'EditView' && ($vardef['type'] == 'relate' || $vardef['type'] == 'parent')) { |
| 147 | 147 | |
| 148 | - $contents = str_replace('"' . $vardef['id_name'] . '"', '{/literal}"{$fields.' . $vardef['name'] . '.id_name}"{literal}', $contents); |
|
| 149 | - $contents = str_replace('"' . $vardef['name'] . '"', '{/literal}"{$fields.' . $vardef['name'] . '.name}"{literal}', $contents); |
|
| 148 | + $contents = str_replace('"'.$vardef['id_name'].'"', '{/literal}"{$fields.'.$vardef['name'].'.id_name}"{literal}', $contents); |
|
| 149 | + $contents = str_replace('"'.$vardef['name'].'"', '{/literal}"{$fields.'.$vardef['name'].'.name}"{literal}', $contents); |
|
| 150 | 150 | // regex below fixes button javascript for flexi relationship |
| 151 | - if($vardef['type'] == 'parent') { |
|
| 151 | + if ($vardef['type'] == 'parent') { |
|
| 152 | 152 | $contents = str_replace("onclick='open_popup(document.{\$form_name}.parent_type.value, 600, 400, \"\", true, false, {literal}{\"call_back_function\":\"set_return\",\"form_name\":\"EditView\",\"field_to_name_array\":{\"id\":{/literal}\"{\$fields.parent_name.id_name}", "onclick='open_popup(document.{\$form_name}.parent_type.value, 600, 400, \"\", true, false, {literal}{\"call_back_function\":\"set_return\",\"form_name\":\"EditView\",\"field_to_name_array\":{\"id\":{/literal}\"parent_id", $contents); |
| 153 | 153 | } |
| 154 | 154 | } |
@@ -182,10 +182,10 @@ discard block |
||
| 182 | 182 | } |
| 183 | 183 | $t23 = strpos($time_format, '23') !== false ? '%H' : '%I'; |
| 184 | 184 | if (!isset($match[2]) || $match[2] == '') { |
| 185 | - $ss->assign('CALENDAR_FORMAT', $date_format . ' ' . $t23 . $time_separator . "%M"); |
|
| 185 | + $ss->assign('CALENDAR_FORMAT', $date_format.' '.$t23.$time_separator."%M"); |
|
| 186 | 186 | } else { |
| 187 | 187 | $pm = $match[2] == "pm" ? "%P" : "%p"; |
| 188 | - $ss->assign('CALENDAR_FORMAT', $date_format . ' ' . $t23 . $time_separator . "%M" . $pm); |
|
| 188 | + $ss->assign('CALENDAR_FORMAT', $date_format.' '.$t23.$time_separator."%M".$pm); |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | $ss->assign('CALENDAR_FDOW', $current_user->get_first_day_of_week()); |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | if ($fieldlist[$fieldname]['type'] == 'link') { |
| 227 | - $fieldlist[$fieldname]['id_name'] = $fieldlist[$fieldname]['name'] . '_id'; |
|
| 227 | + $fieldlist[$fieldname]['id_name'] = $fieldlist[$fieldname]['name'].'_id'; |
|
| 228 | 228 | |
| 229 | 229 | if ((!isset($fieldlist[$fieldname]['module']) || $fieldlist[$fieldname]['module'] == '') && $focus->load_relationship($fieldlist[$fieldname]['name'])) { |
| 230 | 230 | $relateField = $fieldlist[$fieldname]['name']; |
@@ -232,7 +232,7 @@ discard block |
||
| 232 | 232 | } |
| 233 | 233 | } |
| 234 | 234 | |
| 235 | - if($fieldlist[$fieldname]['type'] == 'parent'){ |
|
| 235 | + if ($fieldlist[$fieldname]['type'] == 'parent') { |
|
| 236 | 236 | $fieldlist['parent_id']['name'] = 'parent_id'; |
| 237 | 237 | } |
| 238 | 238 | |
@@ -243,15 +243,15 @@ discard block |
||
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | if (isset($fieldlist[$fieldname]['id_name']) && $fieldlist[$fieldname]['id_name'] != '' && $fieldlist[$fieldname]['id_name'] != $fieldlist[$fieldname]['name']) { |
| 246 | - if($value){ |
|
| 246 | + if ($value) { |
|
| 247 | 247 | $relateIdField = $fieldlist[$fieldname]['id_name']; |
| 248 | - $rel_value = $bean->$relateIdField; |
|
| 248 | + $rel_value = $bean->$relateIdField; |
|
| 249 | 249 | |
| 250 | 250 | } |
| 251 | 251 | $fieldlist[$fieldlist[$fieldname]['id_name']]['value'] = $rel_value; |
| 252 | 252 | $fieldlist[$fieldname]['value'] = $value; |
| 253 | 253 | $fieldlist[$fieldname]['id_name'] = $aow_field; |
| 254 | - $fieldlist[$fieldname]['name'] = $aow_field . '_display'; |
|
| 254 | + $fieldlist[$fieldname]['name'] = $aow_field.'_display'; |
|
| 255 | 255 | } else if (isset($fieldlist[$fieldname]['type']) && ($fieldlist[$fieldname]['type'] == 'datetimecombo' || $fieldlist[$fieldname]['type'] == 'datetime')) { |
| 256 | 256 | $value = $focus->convertField($value, $fieldlist[$fieldname]); |
| 257 | 257 | if (!$value) { |
@@ -323,29 +323,29 @@ discard block |
||
| 323 | 323 | |
| 324 | 324 | if ($bean->field_defs[$field]['type'] == "multienum") { |
| 325 | 325 | $bean->$field = encodeMultienumValue($value); |
| 326 | - }else if ($bean->field_defs[$field]['type'] == "relate" || $bean->field_defs[$field]['type'] == 'parent'){ |
|
| 326 | + } else if ($bean->field_defs[$field]['type'] == "relate" || $bean->field_defs[$field]['type'] == 'parent') { |
|
| 327 | 327 | $save_field = $bean->field_defs[$field]['id_name']; |
| 328 | 328 | $bean->$save_field = $value; |
| 329 | 329 | if ($bean->field_defs[$field]['type'] == 'parent') { |
| 330 | 330 | $bean->parent_type = $_REQUEST['parent_type']; |
| 331 | 331 | $bean->fill_in_additional_parent_fields(); // get up to date parent info as need it to display name |
| 332 | 332 | } |
| 333 | - }else if ($bean->field_defs[$field]['type'] == "currency"){ |
|
| 333 | + } else if ($bean->field_defs[$field]['type'] == "currency") { |
|
| 334 | 334 | if (stripos($field, 'usdollar')) { |
| 335 | 335 | $newfield = str_replace("_usdollar", "", $field); |
| 336 | 336 | $bean->$newfield = $value; |
| 337 | 337 | } |
| 338 | - else{ |
|
| 338 | + else { |
|
| 339 | 339 | $bean->$field = $value; |
| 340 | 340 | } |
| 341 | 341 | |
| 342 | - }else{ |
|
| 342 | + } else { |
|
| 343 | 343 | $bean->$field = $value; |
| 344 | 344 | } |
| 345 | 345 | |
| 346 | 346 | $check_notify = FALSE; |
| 347 | 347 | |
| 348 | - if (isset( $bean->fetched_row['assigned_user_id']) && $field == "assigned_user_name") { |
|
| 348 | + if (isset($bean->fetched_row['assigned_user_id']) && $field == "assigned_user_name") { |
|
| 349 | 349 | $old_assigned_user_id = $bean->fetched_row['assigned_user_id']; |
| 350 | 350 | if (!empty($value) && ($old_assigned_user_id != $value) && ($value != $current_user->id)) { |
| 351 | 351 | $check_notify = TRUE; |
@@ -355,12 +355,12 @@ discard block |
||
| 355 | 355 | $adminOnlyModules = array('Users', 'Employees'); |
| 356 | 356 | |
| 357 | 357 | $enabled = true; |
| 358 | - if(in_array($module, $adminOnlyModules) && !is_admin($current_user)) { |
|
| 358 | + if (in_array($module, $adminOnlyModules) && !is_admin($current_user)) { |
|
| 359 | 359 | $enabled = false; |
| 360 | 360 | } |
| 361 | 361 | |
| 362 | - if(($bean->ACLAccess("edit") || is_admin($current_user)) && $enabled) { |
|
| 363 | - if(!$bean->save($check_notify)) { |
|
| 362 | + if (($bean->ACLAccess("edit") || is_admin($current_user)) && $enabled) { |
|
| 363 | + if (!$bean->save($check_notify)) { |
|
| 364 | 364 | $GLOBALS['log']->fatal("Saving probably failed or bean->save() method did not return with a positive result."); |
| 365 | 365 | } |
| 366 | 366 | } else { |
@@ -385,7 +385,7 @@ discard block |
||
| 385 | 385 | |
| 386 | 386 | $fieldlist[$field] = $bean->getFieldDefinition($field); |
| 387 | 387 | |
| 388 | - if(is_array($listViewDefs)){ |
|
| 388 | + if (is_array($listViewDefs)) { |
|
| 389 | 389 | $fieldlist[$field] = array_merge($fieldlist[$field], $listViewDefs); |
| 390 | 390 | } |
| 391 | 391 | |
@@ -423,7 +423,7 @@ discard block |
||
| 423 | 423 | $vardef['module'] = $bean->module_dir; |
| 424 | 424 | |
| 425 | 425 | $SugarWidgetSubPanelDetailViewLink = new SugarWidgetSubPanelDetailViewLink($vardef); |
| 426 | - $value = "<b>" . $SugarWidgetSubPanelDetailViewLink->displayList($vardef) . "</b>"; |
|
| 426 | + $value = "<b>".$SugarWidgetSubPanelDetailViewLink->displayList($vardef)."</b>"; |
|
| 427 | 427 | |
| 428 | 428 | } |
| 429 | 429 | |
@@ -436,7 +436,7 @@ discard block |
||
| 436 | 436 | } |
| 437 | 437 | $datetime_format = $timedate->get_date_time_format(); |
| 438 | 438 | // create utc date (as it's utc in db) |
| 439 | - $datetime = DateTime::createFromFormat("Y-m-d H:i:s", $value,new DateTimeZone('UTC')); |
|
| 439 | + $datetime = DateTime::createFromFormat("Y-m-d H:i:s", $value, new DateTimeZone('UTC')); |
|
| 440 | 440 | // convert it to timezone the user uses |
| 441 | 441 | $datetime = $timedate->tzUser($datetime); |
| 442 | 442 | |
@@ -475,24 +475,24 @@ discard block |
||
| 475 | 475 | } |
| 476 | 476 | |
| 477 | 477 | //if field is of type relate. |
| 478 | - if ($vardef['type'] == "relate" || $vardef['type'] == "parent") { |
|
| 478 | + if ($vardef['type'] == "relate" || $vardef['type'] == "parent") { |
|
| 479 | 479 | |
| 480 | - if($vardef['source'] == "non-db"){ |
|
| 480 | + if ($vardef['source'] == "non-db") { |
|
| 481 | 481 | |
| 482 | - if($vardef['module'] == "Employees"){ |
|
| 482 | + if ($vardef['module'] == "Employees") { |
|
| 483 | 483 | $vardef['ext2'] = "Users"; |
| 484 | 484 | $vardef['rname'] = "full_name"; |
| 485 | 485 | } |
| 486 | 486 | |
| 487 | 487 | } |
| 488 | - if($vardef['type'] == "parent") { |
|
| 488 | + if ($vardef['type'] == "parent") { |
|
| 489 | 489 | $vardef['module'] = $bean->parent_type; |
| 490 | 490 | $name = $bean->parent_name; |
| 491 | 491 | } |
| 492 | 492 | $idName = $vardef['id_name']; |
| 493 | 493 | $record = $bean->$idName; |
| 494 | 494 | |
| 495 | - if($vardef['name'] != "assigned_user_name") { |
|
| 495 | + if ($vardef['name'] != "assigned_user_name") { |
|
| 496 | 496 | $value = "<a class=\"listViewTdLinkS1\" href=\"index.php?action=DetailView&module=".$vardef['module']."&record=$record\">"; |
| 497 | 497 | } else { |
| 498 | 498 | $value = ""; |
@@ -500,32 +500,32 @@ discard block |
||
| 500 | 500 | |
| 501 | 501 | |
| 502 | 502 | //To fix github bug 880 (the rname was null and was causing a 500 error in the getFieldValueFromModule call to $fieldname |
| 503 | - $fieldName = 'name';//$vardef['name']; |
|
| 504 | - if(!is_null($vardef['rname'])) |
|
| 503 | + $fieldName = 'name'; //$vardef['name']; |
|
| 504 | + if (!is_null($vardef['rname'])) |
|
| 505 | 505 | $fieldName = $vardef['rname']; |
| 506 | 506 | |
| 507 | - if($vardef['ext2']){ |
|
| 507 | + if ($vardef['ext2']) { |
|
| 508 | 508 | |
| 509 | - $value .= getFieldValueFromModule($fieldName,$vardef['ext2'],$record); |
|
| 509 | + $value .= getFieldValueFromModule($fieldName, $vardef['ext2'], $record); |
|
| 510 | 510 | |
| 511 | - } else if(!empty($vardef['rname']) || $vardef['name'] == "related_doc_name") { |
|
| 512 | - $value .= getFieldValueFromModule($fieldName,$vardef['module'],$record); |
|
| 511 | + } else if (!empty($vardef['rname']) || $vardef['name'] == "related_doc_name") { |
|
| 512 | + $value .= getFieldValueFromModule($fieldName, $vardef['module'], $record); |
|
| 513 | 513 | |
| 514 | 514 | } else { |
| 515 | 515 | $value .= $name; |
| 516 | 516 | } |
| 517 | 517 | |
| 518 | - if($vardef['name'] != "assigned_user_name") { |
|
| 518 | + if ($vardef['name'] != "assigned_user_name") { |
|
| 519 | 519 | $value .= "</a>"; |
| 520 | 520 | } |
| 521 | 521 | } |
| 522 | - if($vardef['type'] == "url") |
|
| 522 | + if ($vardef['type'] == "url") |
|
| 523 | 523 | { |
| 524 | 524 | $value = '<a href='.$value.' target="_blank">'.$value.'</a>'; |
| 525 | 525 | } |
| 526 | 526 | |
| 527 | - if($vardef['type'] == "currency"){ |
|
| 528 | - if($_REQUEST['view'] != "DetailView"){ |
|
| 527 | + if ($vardef['type'] == "currency") { |
|
| 528 | + if ($_REQUEST['view'] != "DetailView") { |
|
| 529 | 529 | $value = currency_format_number($value); |
| 530 | 530 | } |
| 531 | 531 | else |
@@ -538,7 +538,7 @@ discard block |
||
| 538 | 538 | function getFieldValueFromModule($fieldname, $module, $id) |
| 539 | 539 | { |
| 540 | 540 | //Github bug 880, if the fieldname is null, do no call from bean |
| 541 | - if(is_null($fieldname)) |
|
| 541 | + if (is_null($fieldname)) |
|
| 542 | 542 | return ''; |
| 543 | 543 | |
| 544 | 544 | $bean = BeanFactory::getBean($module, $id); |
@@ -559,11 +559,11 @@ discard block |
||
| 559 | 559 | return $value; |
| 560 | 560 | } |
| 561 | 561 | |
| 562 | -function checkAccess($bean){ |
|
| 562 | +function checkAccess($bean) { |
|
| 563 | 563 | |
| 564 | - if($bean->ACLAccess('EditView')) { |
|
| 564 | + if ($bean->ACLAccess('EditView')) { |
|
| 565 | 565 | return true; |
| 566 | - }else { |
|
| 566 | + } else { |
|
| 567 | 567 | return false; |
| 568 | 568 | } |
| 569 | 569 | } |
@@ -100,368 +100,368 @@ discard block |
||
| 100 | 100 | */ |
| 101 | 101 | class MysqlManager extends DBManager |
| 102 | 102 | { |
| 103 | - /** |
|
| 104 | - * @see DBManager::$dbType |
|
| 105 | - */ |
|
| 106 | - public $dbType = 'mysql'; |
|
| 107 | - public $variant = 'mysql'; |
|
| 108 | - public $dbName = 'MySQL'; |
|
| 109 | - public $label = 'LBL_MYSQL'; |
|
| 110 | - |
|
| 111 | - protected $maxNameLengths = array( |
|
| 112 | - 'table' => 64, |
|
| 113 | - 'column' => 64, |
|
| 114 | - 'index' => 64, |
|
| 115 | - 'alias' => 256 |
|
| 116 | - ); |
|
| 117 | - |
|
| 118 | - protected $type_map = array( |
|
| 119 | - 'int' => 'int', |
|
| 120 | - 'double' => 'double', |
|
| 121 | - 'float' => 'float', |
|
| 122 | - 'uint' => 'int unsigned', |
|
| 123 | - 'ulong' => 'bigint unsigned', |
|
| 124 | - 'long' => 'bigint', |
|
| 125 | - 'short' => 'smallint', |
|
| 126 | - 'varchar' => 'varchar', |
|
| 127 | - 'text' => 'text', |
|
| 128 | - 'longtext' => 'longtext', |
|
| 129 | - 'date' => 'date', |
|
| 130 | - 'enum' => 'varchar', |
|
| 131 | - 'relate' => 'varchar', |
|
| 132 | - 'multienum'=> 'text', |
|
| 133 | - 'html' => 'text', |
|
| 134 | - 'longhtml' => 'longtext', |
|
| 135 | - 'datetime' => 'datetime', |
|
| 136 | - 'datetimecombo' => 'datetime', |
|
| 137 | - 'time' => 'time', |
|
| 138 | - 'bool' => 'bool', |
|
| 139 | - 'tinyint' => 'tinyint', |
|
| 140 | - 'char' => 'char', |
|
| 141 | - 'blob' => 'blob', |
|
| 142 | - 'longblob' => 'longblob', |
|
| 143 | - 'currency' => 'decimal(26,6)', |
|
| 144 | - 'decimal' => 'decimal', |
|
| 145 | - 'decimal2' => 'decimal', |
|
| 146 | - 'id' => 'char(36)', |
|
| 147 | - 'url' => 'varchar', |
|
| 148 | - 'encrypt' => 'varchar', |
|
| 149 | - 'file' => 'varchar', |
|
| 150 | - 'decimal_tpl' => 'decimal(%d, %d)', |
|
| 151 | - |
|
| 152 | - ); |
|
| 153 | - |
|
| 154 | - protected $capabilities = array( |
|
| 155 | - "affected_rows" => true, |
|
| 156 | - "select_rows" => true, |
|
| 157 | - "inline_keys" => true, |
|
| 158 | - "create_user" => true, |
|
| 159 | - "fulltext" => true, |
|
| 160 | - "collation" => true, |
|
| 161 | - "create_db" => true, |
|
| 162 | - "disable_keys" => true, |
|
| 163 | - ); |
|
| 164 | - |
|
| 165 | - /** |
|
| 166 | - * Parses and runs queries |
|
| 167 | - * |
|
| 168 | - * @param string $sql SQL Statement to execute |
|
| 169 | - * @param bool $dieOnError True if we want to call die if the query returns errors |
|
| 170 | - * @param string $msg Message to log if error occurs |
|
| 171 | - * @param bool $suppress Flag to suppress all error output unless in debug logging mode. |
|
| 172 | - * @param bool $keepResult True if we want to push this result into the $lastResult array. |
|
| 173 | - * @return resource result set |
|
| 174 | - */ |
|
| 175 | - public function query($sql, $dieOnError = false, $msg = '', $suppress = false, $keepResult = false) |
|
| 176 | - { |
|
| 177 | - if(is_array($sql)) { |
|
| 178 | - return $this->queryArray($sql, $dieOnError, $msg, $suppress); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - parent::countQuery($sql); |
|
| 182 | - $GLOBALS['log']->info('Query:' . $sql); |
|
| 183 | - $this->checkConnection(); |
|
| 184 | - $this->query_time = microtime(true); |
|
| 185 | - $this->lastsql = $sql; |
|
| 186 | - $result = $suppress?@mysql_query($sql, $this->database):mysql_query($sql, $this->database); |
|
| 187 | - |
|
| 188 | - $this->query_time = microtime(true) - $this->query_time; |
|
| 189 | - $GLOBALS['log']->info('Query Execution Time:'.$this->query_time); |
|
| 190 | - |
|
| 191 | - |
|
| 192 | - if($keepResult) |
|
| 193 | - $this->lastResult = $result; |
|
| 194 | - |
|
| 195 | - $this->checkError($msg.' Query Failed:' . $sql . '::', $dieOnError); |
|
| 196 | - return $result; |
|
| 197 | - } |
|
| 103 | + /** |
|
| 104 | + * @see DBManager::$dbType |
|
| 105 | + */ |
|
| 106 | + public $dbType = 'mysql'; |
|
| 107 | + public $variant = 'mysql'; |
|
| 108 | + public $dbName = 'MySQL'; |
|
| 109 | + public $label = 'LBL_MYSQL'; |
|
| 110 | + |
|
| 111 | + protected $maxNameLengths = array( |
|
| 112 | + 'table' => 64, |
|
| 113 | + 'column' => 64, |
|
| 114 | + 'index' => 64, |
|
| 115 | + 'alias' => 256 |
|
| 116 | + ); |
|
| 117 | + |
|
| 118 | + protected $type_map = array( |
|
| 119 | + 'int' => 'int', |
|
| 120 | + 'double' => 'double', |
|
| 121 | + 'float' => 'float', |
|
| 122 | + 'uint' => 'int unsigned', |
|
| 123 | + 'ulong' => 'bigint unsigned', |
|
| 124 | + 'long' => 'bigint', |
|
| 125 | + 'short' => 'smallint', |
|
| 126 | + 'varchar' => 'varchar', |
|
| 127 | + 'text' => 'text', |
|
| 128 | + 'longtext' => 'longtext', |
|
| 129 | + 'date' => 'date', |
|
| 130 | + 'enum' => 'varchar', |
|
| 131 | + 'relate' => 'varchar', |
|
| 132 | + 'multienum'=> 'text', |
|
| 133 | + 'html' => 'text', |
|
| 134 | + 'longhtml' => 'longtext', |
|
| 135 | + 'datetime' => 'datetime', |
|
| 136 | + 'datetimecombo' => 'datetime', |
|
| 137 | + 'time' => 'time', |
|
| 138 | + 'bool' => 'bool', |
|
| 139 | + 'tinyint' => 'tinyint', |
|
| 140 | + 'char' => 'char', |
|
| 141 | + 'blob' => 'blob', |
|
| 142 | + 'longblob' => 'longblob', |
|
| 143 | + 'currency' => 'decimal(26,6)', |
|
| 144 | + 'decimal' => 'decimal', |
|
| 145 | + 'decimal2' => 'decimal', |
|
| 146 | + 'id' => 'char(36)', |
|
| 147 | + 'url' => 'varchar', |
|
| 148 | + 'encrypt' => 'varchar', |
|
| 149 | + 'file' => 'varchar', |
|
| 150 | + 'decimal_tpl' => 'decimal(%d, %d)', |
|
| 151 | + |
|
| 152 | + ); |
|
| 153 | + |
|
| 154 | + protected $capabilities = array( |
|
| 155 | + "affected_rows" => true, |
|
| 156 | + "select_rows" => true, |
|
| 157 | + "inline_keys" => true, |
|
| 158 | + "create_user" => true, |
|
| 159 | + "fulltext" => true, |
|
| 160 | + "collation" => true, |
|
| 161 | + "create_db" => true, |
|
| 162 | + "disable_keys" => true, |
|
| 163 | + ); |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * Parses and runs queries |
|
| 167 | + * |
|
| 168 | + * @param string $sql SQL Statement to execute |
|
| 169 | + * @param bool $dieOnError True if we want to call die if the query returns errors |
|
| 170 | + * @param string $msg Message to log if error occurs |
|
| 171 | + * @param bool $suppress Flag to suppress all error output unless in debug logging mode. |
|
| 172 | + * @param bool $keepResult True if we want to push this result into the $lastResult array. |
|
| 173 | + * @return resource result set |
|
| 174 | + */ |
|
| 175 | + public function query($sql, $dieOnError = false, $msg = '', $suppress = false, $keepResult = false) |
|
| 176 | + { |
|
| 177 | + if(is_array($sql)) { |
|
| 178 | + return $this->queryArray($sql, $dieOnError, $msg, $suppress); |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + parent::countQuery($sql); |
|
| 182 | + $GLOBALS['log']->info('Query:' . $sql); |
|
| 183 | + $this->checkConnection(); |
|
| 184 | + $this->query_time = microtime(true); |
|
| 185 | + $this->lastsql = $sql; |
|
| 186 | + $result = $suppress?@mysql_query($sql, $this->database):mysql_query($sql, $this->database); |
|
| 187 | + |
|
| 188 | + $this->query_time = microtime(true) - $this->query_time; |
|
| 189 | + $GLOBALS['log']->info('Query Execution Time:'.$this->query_time); |
|
| 190 | + |
|
| 191 | + |
|
| 192 | + if($keepResult) |
|
| 193 | + $this->lastResult = $result; |
|
| 194 | + |
|
| 195 | + $this->checkError($msg.' Query Failed:' . $sql . '::', $dieOnError); |
|
| 196 | + return $result; |
|
| 197 | + } |
|
| 198 | 198 | |
| 199 | 199 | /** |
| 200 | 200 | * Returns the number of rows affected by the last query |
| 201 | 201 | * @param $result |
| 202 | 202 | * @return int |
| 203 | 203 | */ |
| 204 | - public function getAffectedRowCount($result) |
|
| 205 | - { |
|
| 206 | - return mysql_affected_rows($this->getDatabase()); |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * Returns the number of rows returned by the result |
|
| 211 | - * |
|
| 212 | - * This function can't be reliably implemented on most DB, do not use it. |
|
| 213 | - * @abstract |
|
| 214 | - * @deprecated |
|
| 215 | - * @param resource $result |
|
| 216 | - * @return int |
|
| 217 | - */ |
|
| 218 | - public function getRowCount($result) |
|
| 219 | - { |
|
| 220 | - return mysql_num_rows($result); |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - /** |
|
| 224 | - * Disconnects from the database |
|
| 225 | - * |
|
| 226 | - * Also handles any cleanup needed |
|
| 227 | - */ |
|
| 228 | - public function disconnect() |
|
| 229 | - { |
|
| 230 | - $GLOBALS['log']->debug('Calling MySQL::disconnect()'); |
|
| 231 | - if(!empty($this->database)){ |
|
| 232 | - $this->freeResult(); |
|
| 233 | - mysql_close($this->database); |
|
| 234 | - $this->database = null; |
|
| 235 | - } |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - /** |
|
| 239 | - * @see DBManager::freeDbResult() |
|
| 240 | - */ |
|
| 241 | - protected function freeDbResult($dbResult) |
|
| 242 | - { |
|
| 243 | - if(!empty($dbResult)) |
|
| 244 | - mysql_free_result($dbResult); |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - |
|
| 248 | - /** |
|
| 249 | - * @abstract |
|
| 250 | - * Check if query has LIMIT clause |
|
| 251 | - * Relevant for now only for Mysql |
|
| 252 | - * @param string $sql |
|
| 253 | - * @return bool |
|
| 254 | - */ |
|
| 255 | - protected function hasLimit($sql) |
|
| 256 | - { |
|
| 257 | - return stripos($sql, " limit ") !== false; |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - /** |
|
| 261 | - * @see DBManager::limitQuery() |
|
| 262 | - */ |
|
| 263 | - public function limitQuery($sql, $start, $count, $dieOnError = false, $msg = '', $execute = true) |
|
| 264 | - { |
|
| 204 | + public function getAffectedRowCount($result) |
|
| 205 | + { |
|
| 206 | + return mysql_affected_rows($this->getDatabase()); |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * Returns the number of rows returned by the result |
|
| 211 | + * |
|
| 212 | + * This function can't be reliably implemented on most DB, do not use it. |
|
| 213 | + * @abstract |
|
| 214 | + * @deprecated |
|
| 215 | + * @param resource $result |
|
| 216 | + * @return int |
|
| 217 | + */ |
|
| 218 | + public function getRowCount($result) |
|
| 219 | + { |
|
| 220 | + return mysql_num_rows($result); |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + /** |
|
| 224 | + * Disconnects from the database |
|
| 225 | + * |
|
| 226 | + * Also handles any cleanup needed |
|
| 227 | + */ |
|
| 228 | + public function disconnect() |
|
| 229 | + { |
|
| 230 | + $GLOBALS['log']->debug('Calling MySQL::disconnect()'); |
|
| 231 | + if(!empty($this->database)){ |
|
| 232 | + $this->freeResult(); |
|
| 233 | + mysql_close($this->database); |
|
| 234 | + $this->database = null; |
|
| 235 | + } |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + /** |
|
| 239 | + * @see DBManager::freeDbResult() |
|
| 240 | + */ |
|
| 241 | + protected function freeDbResult($dbResult) |
|
| 242 | + { |
|
| 243 | + if(!empty($dbResult)) |
|
| 244 | + mysql_free_result($dbResult); |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + |
|
| 248 | + /** |
|
| 249 | + * @abstract |
|
| 250 | + * Check if query has LIMIT clause |
|
| 251 | + * Relevant for now only for Mysql |
|
| 252 | + * @param string $sql |
|
| 253 | + * @return bool |
|
| 254 | + */ |
|
| 255 | + protected function hasLimit($sql) |
|
| 256 | + { |
|
| 257 | + return stripos($sql, " limit ") !== false; |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + /** |
|
| 261 | + * @see DBManager::limitQuery() |
|
| 262 | + */ |
|
| 263 | + public function limitQuery($sql, $start, $count, $dieOnError = false, $msg = '', $execute = true) |
|
| 264 | + { |
|
| 265 | 265 | $start = (int)$start; |
| 266 | 266 | $count = (int)$count; |
| 267 | - if ($start < 0) |
|
| 268 | - $start = 0; |
|
| 269 | - $GLOBALS['log']->debug('Limit Query:' . $sql. ' Start: ' .$start . ' count: ' . $count); |
|
| 270 | - |
|
| 271 | - $sql = "$sql LIMIT $start,$count"; |
|
| 272 | - $this->lastsql = $sql; |
|
| 273 | - |
|
| 274 | - if(!empty($GLOBALS['sugar_config']['check_query'])){ |
|
| 275 | - $this->checkQuery($sql); |
|
| 276 | - } |
|
| 277 | - if(!$execute) { |
|
| 278 | - return $sql; |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - return $this->query($sql, $dieOnError, $msg); |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - |
|
| 285 | - /** |
|
| 286 | - * @see DBManager::checkQuery() |
|
| 287 | - */ |
|
| 288 | - protected function checkQuery($sql, $object_name = false) |
|
| 289 | - { |
|
| 290 | - $result = $this->query('EXPLAIN ' . $sql); |
|
| 291 | - $badQuery = array(); |
|
| 292 | - while ($row = $this->fetchByAssoc($result)) { |
|
| 293 | - if (empty($row['table'])) |
|
| 294 | - continue; |
|
| 295 | - $badQuery[$row['table']] = ''; |
|
| 296 | - if (strtoupper($row['type']) == 'ALL') |
|
| 297 | - $badQuery[$row['table']] .= ' Full Table Scan;'; |
|
| 298 | - if (empty($row['key'])) |
|
| 299 | - $badQuery[$row['table']] .= ' No Index Key Used;'; |
|
| 300 | - if (!empty($row['Extra']) && substr_count($row['Extra'], 'Using filesort') > 0) |
|
| 301 | - $badQuery[$row['table']] .= ' Using FileSort;'; |
|
| 302 | - if (!empty($row['Extra']) && substr_count($row['Extra'], 'Using temporary') > 0) |
|
| 303 | - $badQuery[$row['table']] .= ' Using Temporary Table;'; |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - if ( empty($badQuery) ) |
|
| 307 | - return true; |
|
| 308 | - |
|
| 309 | - foreach($badQuery as $table=>$data ){ |
|
| 310 | - if(!empty($data)){ |
|
| 311 | - $warning = ' Table:' . $table . ' Data:' . $data; |
|
| 312 | - if(!empty($GLOBALS['sugar_config']['check_query_log'])){ |
|
| 313 | - $GLOBALS['log']->fatal($sql); |
|
| 314 | - $GLOBALS['log']->fatal('CHECK QUERY:' .$warning); |
|
| 315 | - } |
|
| 316 | - else{ |
|
| 317 | - $GLOBALS['log']->warn('CHECK QUERY:' .$warning); |
|
| 318 | - } |
|
| 319 | - } |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - return false; |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - /** |
|
| 326 | - * @see DBManager::get_columns() |
|
| 327 | - */ |
|
| 328 | - public function get_columns($tablename) |
|
| 329 | - { |
|
| 330 | - //find all unique indexes and primary keys. |
|
| 331 | - $result = $this->query("DESCRIBE $tablename"); |
|
| 332 | - |
|
| 333 | - $columns = array(); |
|
| 334 | - while (($row=$this->fetchByAssoc($result)) !=null) { |
|
| 335 | - $name = strtolower($row['Field']); |
|
| 336 | - $columns[$name]['name']=$name; |
|
| 337 | - $matches = array(); |
|
| 338 | - preg_match_all('/(\w+)(?:\(([0-9]+,?[0-9]*)\)|)( unsigned)?/i', $row['Type'], $matches); |
|
| 339 | - $columns[$name]['type']=strtolower($matches[1][0]); |
|
| 340 | - if ( isset($matches[2][0]) && in_array(strtolower($matches[1][0]),array('varchar','char','varchar2','int','decimal','float')) ) |
|
| 341 | - $columns[$name]['len']=strtolower($matches[2][0]); |
|
| 342 | - if ( stristr($row['Extra'],'auto_increment') ) |
|
| 343 | - $columns[$name]['auto_increment'] = '1'; |
|
| 344 | - if ($row['Null'] == 'NO' && !stristr($row['Key'],'PRI')) |
|
| 345 | - $columns[$name]['required'] = 'true'; |
|
| 346 | - if (!empty($row['Default']) ) |
|
| 347 | - $columns[$name]['default'] = $row['Default']; |
|
| 348 | - } |
|
| 349 | - return $columns; |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - /** |
|
| 353 | - * @see DBManager::getFieldsArray() |
|
| 354 | - */ |
|
| 355 | - public function getFieldsArray($result, $make_lower_case=false) |
|
| 356 | - { |
|
| 357 | - $field_array = array(); |
|
| 358 | - |
|
| 359 | - if(empty($result)) |
|
| 360 | - return 0; |
|
| 361 | - |
|
| 362 | - $fields = mysql_num_fields($result); |
|
| 363 | - for ($i=0; $i < $fields; $i++) { |
|
| 364 | - $meta = mysql_fetch_field($result, $i); |
|
| 365 | - if (!$meta) |
|
| 366 | - return array(); |
|
| 367 | - |
|
| 368 | - if($make_lower_case == true) |
|
| 369 | - $meta->name = strtolower($meta->name); |
|
| 370 | - |
|
| 371 | - $field_array[] = $meta->name; |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - return $field_array; |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - /** |
|
| 378 | - * @see DBManager::fetchRow() |
|
| 379 | - */ |
|
| 380 | - public function fetchRow($result) |
|
| 381 | - { |
|
| 382 | - if (empty($result)) return false; |
|
| 383 | - |
|
| 384 | - return mysql_fetch_assoc($result); |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - /** |
|
| 388 | - * @see DBManager::getTablesArray() |
|
| 389 | - */ |
|
| 390 | - public function getTablesArray() |
|
| 391 | - { |
|
| 392 | - $this->log->debug('Fetching table list'); |
|
| 393 | - |
|
| 394 | - if ($this->getDatabase()) { |
|
| 395 | - $tables = array(); |
|
| 396 | - $r = $this->query('SHOW TABLES'); |
|
| 397 | - if (!empty($r)) { |
|
| 398 | - while ($a = $this->fetchByAssoc($r)) { |
|
| 399 | - $row = array_values($a); |
|
| 400 | - $tables[]=$row[0]; |
|
| 401 | - } |
|
| 402 | - return $tables; |
|
| 403 | - } |
|
| 404 | - } |
|
| 405 | - |
|
| 406 | - return false; // no database available |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - /** |
|
| 410 | - * @see DBManager::version() |
|
| 411 | - */ |
|
| 412 | - public function version() |
|
| 413 | - { |
|
| 414 | - return $this->getOne("SELECT version() version"); |
|
| 415 | - } |
|
| 416 | - |
|
| 417 | - /** |
|
| 418 | - * @see DBManager::tableExists() |
|
| 419 | - */ |
|
| 420 | - public function tableExists($tableName) |
|
| 421 | - { |
|
| 422 | - $this->log->info("tableExists: $tableName"); |
|
| 423 | - |
|
| 424 | - if ($this->getDatabase()) { |
|
| 425 | - $result = $this->query("SHOW TABLES LIKE ".$this->quoted($tableName)); |
|
| 426 | - if(empty($result)) return false; |
|
| 427 | - $row = $this->fetchByAssoc($result); |
|
| 428 | - return !empty($row); |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - return false; |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - /** |
|
| 435 | - * Get tables like expression |
|
| 436 | - * @param $like string |
|
| 437 | - * @return array |
|
| 438 | - */ |
|
| 439 | - public function tablesLike($like) |
|
| 440 | - { |
|
| 441 | - if ($this->getDatabase()) { |
|
| 442 | - $tables = array(); |
|
| 443 | - $r = $this->query('SHOW TABLES LIKE '.$this->quoted($like)); |
|
| 444 | - if (!empty($r)) { |
|
| 445 | - while ($a = $this->fetchByAssoc($r)) { |
|
| 446 | - $row = array_values($a); |
|
| 447 | - $tables[]=$row[0]; |
|
| 448 | - } |
|
| 449 | - return $tables; |
|
| 450 | - } |
|
| 451 | - } |
|
| 452 | - return false; |
|
| 453 | - } |
|
| 454 | - |
|
| 455 | - /** |
|
| 456 | - * @see DBManager::quote() |
|
| 457 | - */ |
|
| 458 | - public function quote($string) |
|
| 459 | - { |
|
| 460 | - if(is_array($string)) { |
|
| 461 | - return $this->arrayQuote($string); |
|
| 462 | - } |
|
| 463 | - return mysqli_real_escape_string($this->quoteInternal($string), $this->getDatabase()); |
|
| 464 | - } |
|
| 267 | + if ($start < 0) |
|
| 268 | + $start = 0; |
|
| 269 | + $GLOBALS['log']->debug('Limit Query:' . $sql. ' Start: ' .$start . ' count: ' . $count); |
|
| 270 | + |
|
| 271 | + $sql = "$sql LIMIT $start,$count"; |
|
| 272 | + $this->lastsql = $sql; |
|
| 273 | + |
|
| 274 | + if(!empty($GLOBALS['sugar_config']['check_query'])){ |
|
| 275 | + $this->checkQuery($sql); |
|
| 276 | + } |
|
| 277 | + if(!$execute) { |
|
| 278 | + return $sql; |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + return $this->query($sql, $dieOnError, $msg); |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + |
|
| 285 | + /** |
|
| 286 | + * @see DBManager::checkQuery() |
|
| 287 | + */ |
|
| 288 | + protected function checkQuery($sql, $object_name = false) |
|
| 289 | + { |
|
| 290 | + $result = $this->query('EXPLAIN ' . $sql); |
|
| 291 | + $badQuery = array(); |
|
| 292 | + while ($row = $this->fetchByAssoc($result)) { |
|
| 293 | + if (empty($row['table'])) |
|
| 294 | + continue; |
|
| 295 | + $badQuery[$row['table']] = ''; |
|
| 296 | + if (strtoupper($row['type']) == 'ALL') |
|
| 297 | + $badQuery[$row['table']] .= ' Full Table Scan;'; |
|
| 298 | + if (empty($row['key'])) |
|
| 299 | + $badQuery[$row['table']] .= ' No Index Key Used;'; |
|
| 300 | + if (!empty($row['Extra']) && substr_count($row['Extra'], 'Using filesort') > 0) |
|
| 301 | + $badQuery[$row['table']] .= ' Using FileSort;'; |
|
| 302 | + if (!empty($row['Extra']) && substr_count($row['Extra'], 'Using temporary') > 0) |
|
| 303 | + $badQuery[$row['table']] .= ' Using Temporary Table;'; |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + if ( empty($badQuery) ) |
|
| 307 | + return true; |
|
| 308 | + |
|
| 309 | + foreach($badQuery as $table=>$data ){ |
|
| 310 | + if(!empty($data)){ |
|
| 311 | + $warning = ' Table:' . $table . ' Data:' . $data; |
|
| 312 | + if(!empty($GLOBALS['sugar_config']['check_query_log'])){ |
|
| 313 | + $GLOBALS['log']->fatal($sql); |
|
| 314 | + $GLOBALS['log']->fatal('CHECK QUERY:' .$warning); |
|
| 315 | + } |
|
| 316 | + else{ |
|
| 317 | + $GLOBALS['log']->warn('CHECK QUERY:' .$warning); |
|
| 318 | + } |
|
| 319 | + } |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + return false; |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + /** |
|
| 326 | + * @see DBManager::get_columns() |
|
| 327 | + */ |
|
| 328 | + public function get_columns($tablename) |
|
| 329 | + { |
|
| 330 | + //find all unique indexes and primary keys. |
|
| 331 | + $result = $this->query("DESCRIBE $tablename"); |
|
| 332 | + |
|
| 333 | + $columns = array(); |
|
| 334 | + while (($row=$this->fetchByAssoc($result)) !=null) { |
|
| 335 | + $name = strtolower($row['Field']); |
|
| 336 | + $columns[$name]['name']=$name; |
|
| 337 | + $matches = array(); |
|
| 338 | + preg_match_all('/(\w+)(?:\(([0-9]+,?[0-9]*)\)|)( unsigned)?/i', $row['Type'], $matches); |
|
| 339 | + $columns[$name]['type']=strtolower($matches[1][0]); |
|
| 340 | + if ( isset($matches[2][0]) && in_array(strtolower($matches[1][0]),array('varchar','char','varchar2','int','decimal','float')) ) |
|
| 341 | + $columns[$name]['len']=strtolower($matches[2][0]); |
|
| 342 | + if ( stristr($row['Extra'],'auto_increment') ) |
|
| 343 | + $columns[$name]['auto_increment'] = '1'; |
|
| 344 | + if ($row['Null'] == 'NO' && !stristr($row['Key'],'PRI')) |
|
| 345 | + $columns[$name]['required'] = 'true'; |
|
| 346 | + if (!empty($row['Default']) ) |
|
| 347 | + $columns[$name]['default'] = $row['Default']; |
|
| 348 | + } |
|
| 349 | + return $columns; |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + /** |
|
| 353 | + * @see DBManager::getFieldsArray() |
|
| 354 | + */ |
|
| 355 | + public function getFieldsArray($result, $make_lower_case=false) |
|
| 356 | + { |
|
| 357 | + $field_array = array(); |
|
| 358 | + |
|
| 359 | + if(empty($result)) |
|
| 360 | + return 0; |
|
| 361 | + |
|
| 362 | + $fields = mysql_num_fields($result); |
|
| 363 | + for ($i=0; $i < $fields; $i++) { |
|
| 364 | + $meta = mysql_fetch_field($result, $i); |
|
| 365 | + if (!$meta) |
|
| 366 | + return array(); |
|
| 367 | + |
|
| 368 | + if($make_lower_case == true) |
|
| 369 | + $meta->name = strtolower($meta->name); |
|
| 370 | + |
|
| 371 | + $field_array[] = $meta->name; |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + return $field_array; |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + /** |
|
| 378 | + * @see DBManager::fetchRow() |
|
| 379 | + */ |
|
| 380 | + public function fetchRow($result) |
|
| 381 | + { |
|
| 382 | + if (empty($result)) return false; |
|
| 383 | + |
|
| 384 | + return mysql_fetch_assoc($result); |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + /** |
|
| 388 | + * @see DBManager::getTablesArray() |
|
| 389 | + */ |
|
| 390 | + public function getTablesArray() |
|
| 391 | + { |
|
| 392 | + $this->log->debug('Fetching table list'); |
|
| 393 | + |
|
| 394 | + if ($this->getDatabase()) { |
|
| 395 | + $tables = array(); |
|
| 396 | + $r = $this->query('SHOW TABLES'); |
|
| 397 | + if (!empty($r)) { |
|
| 398 | + while ($a = $this->fetchByAssoc($r)) { |
|
| 399 | + $row = array_values($a); |
|
| 400 | + $tables[]=$row[0]; |
|
| 401 | + } |
|
| 402 | + return $tables; |
|
| 403 | + } |
|
| 404 | + } |
|
| 405 | + |
|
| 406 | + return false; // no database available |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + /** |
|
| 410 | + * @see DBManager::version() |
|
| 411 | + */ |
|
| 412 | + public function version() |
|
| 413 | + { |
|
| 414 | + return $this->getOne("SELECT version() version"); |
|
| 415 | + } |
|
| 416 | + |
|
| 417 | + /** |
|
| 418 | + * @see DBManager::tableExists() |
|
| 419 | + */ |
|
| 420 | + public function tableExists($tableName) |
|
| 421 | + { |
|
| 422 | + $this->log->info("tableExists: $tableName"); |
|
| 423 | + |
|
| 424 | + if ($this->getDatabase()) { |
|
| 425 | + $result = $this->query("SHOW TABLES LIKE ".$this->quoted($tableName)); |
|
| 426 | + if(empty($result)) return false; |
|
| 427 | + $row = $this->fetchByAssoc($result); |
|
| 428 | + return !empty($row); |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + return false; |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + /** |
|
| 435 | + * Get tables like expression |
|
| 436 | + * @param $like string |
|
| 437 | + * @return array |
|
| 438 | + */ |
|
| 439 | + public function tablesLike($like) |
|
| 440 | + { |
|
| 441 | + if ($this->getDatabase()) { |
|
| 442 | + $tables = array(); |
|
| 443 | + $r = $this->query('SHOW TABLES LIKE '.$this->quoted($like)); |
|
| 444 | + if (!empty($r)) { |
|
| 445 | + while ($a = $this->fetchByAssoc($r)) { |
|
| 446 | + $row = array_values($a); |
|
| 447 | + $tables[]=$row[0]; |
|
| 448 | + } |
|
| 449 | + return $tables; |
|
| 450 | + } |
|
| 451 | + } |
|
| 452 | + return false; |
|
| 453 | + } |
|
| 454 | + |
|
| 455 | + /** |
|
| 456 | + * @see DBManager::quote() |
|
| 457 | + */ |
|
| 458 | + public function quote($string) |
|
| 459 | + { |
|
| 460 | + if(is_array($string)) { |
|
| 461 | + return $this->arrayQuote($string); |
|
| 462 | + } |
|
| 463 | + return mysqli_real_escape_string($this->quoteInternal($string), $this->getDatabase()); |
|
| 464 | + } |
|
| 465 | 465 | |
| 466 | 466 | /** |
| 467 | 467 | * @see DBManager::quoteIdentifier() |
@@ -471,272 +471,272 @@ discard block |
||
| 471 | 471 | return '`'.$string.'`'; |
| 472 | 472 | } |
| 473 | 473 | |
| 474 | - /** |
|
| 475 | - * @see DBManager::connect() |
|
| 476 | - */ |
|
| 477 | - public function connect(array $configOptions = null, $dieOnError = false) |
|
| 478 | - { |
|
| 479 | - global $sugar_config; |
|
| 480 | - |
|
| 481 | - if(is_null($configOptions)) |
|
| 482 | - $configOptions = $sugar_config['dbconfig']; |
|
| 483 | - |
|
| 484 | - if ($this->getOption('persistent')) { |
|
| 485 | - $this->database = @mysql_pconnect( |
|
| 486 | - $configOptions['db_host_name'], |
|
| 487 | - $configOptions['db_user_name'], |
|
| 488 | - $configOptions['db_password'] |
|
| 489 | - ); |
|
| 490 | - } |
|
| 491 | - |
|
| 492 | - if (!$this->database) { |
|
| 493 | - $this->database = mysql_connect( |
|
| 494 | - $configOptions['db_host_name'], |
|
| 495 | - $configOptions['db_user_name'], |
|
| 496 | - $configOptions['db_password'] |
|
| 497 | - ); |
|
| 498 | - if(empty($this->database)) { |
|
| 499 | - $GLOBALS['log']->fatal("Could not connect to server ".$configOptions['db_host_name']." as ".$configOptions['db_user_name'].":".mysql_error()); |
|
| 500 | - if($dieOnError) { |
|
| 501 | - if(isset($GLOBALS['app_strings']['ERR_NO_DB'])) { |
|
| 502 | - sugar_die($GLOBALS['app_strings']['ERR_NO_DB']); |
|
| 503 | - } else { |
|
| 504 | - sugar_die("Could not connect to the database. Please refer to suitecrm.log for details."); |
|
| 505 | - } |
|
| 506 | - } else { |
|
| 507 | - return false; |
|
| 508 | - } |
|
| 509 | - } |
|
| 510 | - // Do not pass connection information because we have not connected yet |
|
| 511 | - if($this->database && $this->getOption('persistent')){ |
|
| 512 | - $_SESSION['administrator_error'] = "<b>Severe Performance Degradation: Persistent Database Connections " |
|
| 513 | - . "not working. Please set \$sugar_config['dbconfigoption']['persistent'] to false " |
|
| 514 | - . "in your config.php file</b>"; |
|
| 515 | - } |
|
| 516 | - } |
|
| 517 | - if(!empty($configOptions['db_name']) && !@mysql_select_db($configOptions['db_name'])) { |
|
| 518 | - $GLOBALS['log']->fatal( "Unable to select database {$configOptions['db_name']}: " . mysql_error($this->database)); |
|
| 519 | - if($dieOnError) { |
|
| 520 | - sugar_die($GLOBALS['app_strings']['ERR_NO_DB']); |
|
| 521 | - } else { |
|
| 522 | - return false; |
|
| 523 | - } |
|
| 524 | - } |
|
| 525 | - |
|
| 526 | - // cn: using direct calls to prevent this from spamming the Logs |
|
| 527 | - mysql_query("SET CHARACTER SET utf8", $this->database); |
|
| 528 | - $names = "SET NAMES 'utf8'"; |
|
| 529 | - $collation = $this->getOption('collation'); |
|
| 530 | - if(!empty($collation)) { |
|
| 531 | - $names .= " COLLATE '$collation'"; |
|
| 532 | - } |
|
| 533 | - mysql_query($names, $this->database); |
|
| 534 | - |
|
| 535 | - if(!$this->checkError('Could Not Connect:', $dieOnError)) |
|
| 536 | - $GLOBALS['log']->info("connected to db"); |
|
| 537 | - $this->connectOptions = $configOptions; |
|
| 538 | - |
|
| 539 | - $GLOBALS['log']->info("Connect:".$this->database); |
|
| 540 | - return true; |
|
| 541 | - } |
|
| 542 | - |
|
| 543 | - /** |
|
| 544 | - * @see DBManager::repairTableParams() |
|
| 545 | - * |
|
| 546 | - * For MySQL, we can write the ALTER TABLE statement all in one line, which speeds things |
|
| 547 | - * up quite a bit. So here, we'll parse the returned SQL into a single ALTER TABLE command. |
|
| 548 | - */ |
|
| 549 | - public function repairTableParams($tablename, $fielddefs, $indices, $execute = true, $engine = null) |
|
| 550 | - { |
|
| 551 | - $sql = parent::repairTableParams($tablename,$fielddefs,$indices,false,$engine); |
|
| 552 | - |
|
| 553 | - if ( $sql == '' ) |
|
| 554 | - return ''; |
|
| 555 | - |
|
| 556 | - if ( stristr($sql,'create table') ) |
|
| 557 | - { |
|
| 558 | - if ($execute) { |
|
| 559 | - $msg = "Error creating table: ".$tablename. ":"; |
|
| 560 | - $this->query($sql,true,$msg); |
|
| 561 | - } |
|
| 562 | - return $sql; |
|
| 563 | - } |
|
| 564 | - |
|
| 565 | - // first, parse out all the comments |
|
| 566 | - $match = array(); |
|
| 567 | - preg_match_all('!/\*.*?\*/!is', $sql, $match); |
|
| 568 | - $commentBlocks = $match[0]; |
|
| 569 | - $sql = preg_replace('!/\*.*?\*/!is','', $sql); |
|
| 570 | - |
|
| 571 | - // now, we should only have alter table statements |
|
| 572 | - // let's replace the 'alter table name' part with a comma |
|
| 573 | - $sql = preg_replace("!alter table $tablename!is",', ', $sql); |
|
| 574 | - |
|
| 575 | - // re-add it at the beginning |
|
| 576 | - $sql = substr_replace($sql,'',strpos($sql,','),1); |
|
| 577 | - $sql = str_replace(";","",$sql); |
|
| 578 | - $sql = str_replace("\n","",$sql); |
|
| 579 | - $sql = "ALTER TABLE $tablename $sql"; |
|
| 580 | - |
|
| 581 | - if ( $execute ) |
|
| 582 | - $this->query($sql,'Error with MySQL repair table'); |
|
| 583 | - |
|
| 584 | - // and re-add the comments at the beginning |
|
| 585 | - $sql = implode("\n",$commentBlocks) . "\n". $sql . "\n"; |
|
| 586 | - |
|
| 587 | - return $sql; |
|
| 588 | - } |
|
| 589 | - |
|
| 590 | - /** |
|
| 591 | - * @see DBManager::convert() |
|
| 592 | - */ |
|
| 593 | - public function convert($string, $type, array $additional_parameters = array()) |
|
| 594 | - { |
|
| 595 | - $all_parameters = $additional_parameters; |
|
| 596 | - if(is_array($string)) { |
|
| 597 | - $all_parameters = array_merge($string, $all_parameters); |
|
| 598 | - } elseif (!is_null($string)) { |
|
| 599 | - array_unshift($all_parameters, $string); |
|
| 600 | - } |
|
| 601 | - $all_strings = implode(',', $all_parameters); |
|
| 602 | - |
|
| 603 | - switch (strtolower($type)) { |
|
| 604 | - case 'today': |
|
| 605 | - return "CURDATE()"; |
|
| 606 | - case 'left': |
|
| 607 | - return "LEFT($all_strings)"; |
|
| 608 | - case 'date_format': |
|
| 609 | - if(empty($additional_parameters)) { |
|
| 610 | - return "DATE_FORMAT($string,'%Y-%m-%d')"; |
|
| 611 | - } else { |
|
| 612 | - $format = $additional_parameters[0]; |
|
| 613 | - if($format[0] != "'") { |
|
| 614 | - $format = $this->quoted($format); |
|
| 615 | - } |
|
| 616 | - return "DATE_FORMAT($string,$format)"; |
|
| 617 | - } |
|
| 618 | - case 'ifnull': |
|
| 619 | - if(empty($additional_parameters) && !strstr($all_strings, ",")) { |
|
| 620 | - $all_strings .= ",''"; |
|
| 621 | - } |
|
| 622 | - return "IFNULL($all_strings)"; |
|
| 623 | - case 'concat': |
|
| 624 | - return "CONCAT($all_strings)"; |
|
| 625 | - case 'quarter': |
|
| 626 | - return "QUARTER($string)"; |
|
| 627 | - case "length": |
|
| 628 | - return "LENGTH($string)"; |
|
| 629 | - case 'month': |
|
| 630 | - return "MONTH($string)"; |
|
| 631 | - case 'add_date': |
|
| 632 | - return "DATE_ADD($string, INTERVAL {$additional_parameters[0]} {$additional_parameters[1]})"; |
|
| 633 | - case 'add_time': |
|
| 634 | - return "DATE_ADD($string, INTERVAL + CONCAT({$additional_parameters[0]}, ':', {$additional_parameters[1]}) HOUR_MINUTE)"; |
|
| 474 | + /** |
|
| 475 | + * @see DBManager::connect() |
|
| 476 | + */ |
|
| 477 | + public function connect(array $configOptions = null, $dieOnError = false) |
|
| 478 | + { |
|
| 479 | + global $sugar_config; |
|
| 480 | + |
|
| 481 | + if(is_null($configOptions)) |
|
| 482 | + $configOptions = $sugar_config['dbconfig']; |
|
| 483 | + |
|
| 484 | + if ($this->getOption('persistent')) { |
|
| 485 | + $this->database = @mysql_pconnect( |
|
| 486 | + $configOptions['db_host_name'], |
|
| 487 | + $configOptions['db_user_name'], |
|
| 488 | + $configOptions['db_password'] |
|
| 489 | + ); |
|
| 490 | + } |
|
| 491 | + |
|
| 492 | + if (!$this->database) { |
|
| 493 | + $this->database = mysql_connect( |
|
| 494 | + $configOptions['db_host_name'], |
|
| 495 | + $configOptions['db_user_name'], |
|
| 496 | + $configOptions['db_password'] |
|
| 497 | + ); |
|
| 498 | + if(empty($this->database)) { |
|
| 499 | + $GLOBALS['log']->fatal("Could not connect to server ".$configOptions['db_host_name']." as ".$configOptions['db_user_name'].":".mysql_error()); |
|
| 500 | + if($dieOnError) { |
|
| 501 | + if(isset($GLOBALS['app_strings']['ERR_NO_DB'])) { |
|
| 502 | + sugar_die($GLOBALS['app_strings']['ERR_NO_DB']); |
|
| 503 | + } else { |
|
| 504 | + sugar_die("Could not connect to the database. Please refer to suitecrm.log for details."); |
|
| 505 | + } |
|
| 506 | + } else { |
|
| 507 | + return false; |
|
| 508 | + } |
|
| 509 | + } |
|
| 510 | + // Do not pass connection information because we have not connected yet |
|
| 511 | + if($this->database && $this->getOption('persistent')){ |
|
| 512 | + $_SESSION['administrator_error'] = "<b>Severe Performance Degradation: Persistent Database Connections " |
|
| 513 | + . "not working. Please set \$sugar_config['dbconfigoption']['persistent'] to false " |
|
| 514 | + . "in your config.php file</b>"; |
|
| 515 | + } |
|
| 516 | + } |
|
| 517 | + if(!empty($configOptions['db_name']) && !@mysql_select_db($configOptions['db_name'])) { |
|
| 518 | + $GLOBALS['log']->fatal( "Unable to select database {$configOptions['db_name']}: " . mysql_error($this->database)); |
|
| 519 | + if($dieOnError) { |
|
| 520 | + sugar_die($GLOBALS['app_strings']['ERR_NO_DB']); |
|
| 521 | + } else { |
|
| 522 | + return false; |
|
| 523 | + } |
|
| 524 | + } |
|
| 525 | + |
|
| 526 | + // cn: using direct calls to prevent this from spamming the Logs |
|
| 527 | + mysql_query("SET CHARACTER SET utf8", $this->database); |
|
| 528 | + $names = "SET NAMES 'utf8'"; |
|
| 529 | + $collation = $this->getOption('collation'); |
|
| 530 | + if(!empty($collation)) { |
|
| 531 | + $names .= " COLLATE '$collation'"; |
|
| 532 | + } |
|
| 533 | + mysql_query($names, $this->database); |
|
| 534 | + |
|
| 535 | + if(!$this->checkError('Could Not Connect:', $dieOnError)) |
|
| 536 | + $GLOBALS['log']->info("connected to db"); |
|
| 537 | + $this->connectOptions = $configOptions; |
|
| 538 | + |
|
| 539 | + $GLOBALS['log']->info("Connect:".$this->database); |
|
| 540 | + return true; |
|
| 541 | + } |
|
| 542 | + |
|
| 543 | + /** |
|
| 544 | + * @see DBManager::repairTableParams() |
|
| 545 | + * |
|
| 546 | + * For MySQL, we can write the ALTER TABLE statement all in one line, which speeds things |
|
| 547 | + * up quite a bit. So here, we'll parse the returned SQL into a single ALTER TABLE command. |
|
| 548 | + */ |
|
| 549 | + public function repairTableParams($tablename, $fielddefs, $indices, $execute = true, $engine = null) |
|
| 550 | + { |
|
| 551 | + $sql = parent::repairTableParams($tablename,$fielddefs,$indices,false,$engine); |
|
| 552 | + |
|
| 553 | + if ( $sql == '' ) |
|
| 554 | + return ''; |
|
| 555 | + |
|
| 556 | + if ( stristr($sql,'create table') ) |
|
| 557 | + { |
|
| 558 | + if ($execute) { |
|
| 559 | + $msg = "Error creating table: ".$tablename. ":"; |
|
| 560 | + $this->query($sql,true,$msg); |
|
| 561 | + } |
|
| 562 | + return $sql; |
|
| 563 | + } |
|
| 564 | + |
|
| 565 | + // first, parse out all the comments |
|
| 566 | + $match = array(); |
|
| 567 | + preg_match_all('!/\*.*?\*/!is', $sql, $match); |
|
| 568 | + $commentBlocks = $match[0]; |
|
| 569 | + $sql = preg_replace('!/\*.*?\*/!is','', $sql); |
|
| 570 | + |
|
| 571 | + // now, we should only have alter table statements |
|
| 572 | + // let's replace the 'alter table name' part with a comma |
|
| 573 | + $sql = preg_replace("!alter table $tablename!is",', ', $sql); |
|
| 574 | + |
|
| 575 | + // re-add it at the beginning |
|
| 576 | + $sql = substr_replace($sql,'',strpos($sql,','),1); |
|
| 577 | + $sql = str_replace(";","",$sql); |
|
| 578 | + $sql = str_replace("\n","",$sql); |
|
| 579 | + $sql = "ALTER TABLE $tablename $sql"; |
|
| 580 | + |
|
| 581 | + if ( $execute ) |
|
| 582 | + $this->query($sql,'Error with MySQL repair table'); |
|
| 583 | + |
|
| 584 | + // and re-add the comments at the beginning |
|
| 585 | + $sql = implode("\n",$commentBlocks) . "\n". $sql . "\n"; |
|
| 586 | + |
|
| 587 | + return $sql; |
|
| 588 | + } |
|
| 589 | + |
|
| 590 | + /** |
|
| 591 | + * @see DBManager::convert() |
|
| 592 | + */ |
|
| 593 | + public function convert($string, $type, array $additional_parameters = array()) |
|
| 594 | + { |
|
| 595 | + $all_parameters = $additional_parameters; |
|
| 596 | + if(is_array($string)) { |
|
| 597 | + $all_parameters = array_merge($string, $all_parameters); |
|
| 598 | + } elseif (!is_null($string)) { |
|
| 599 | + array_unshift($all_parameters, $string); |
|
| 600 | + } |
|
| 601 | + $all_strings = implode(',', $all_parameters); |
|
| 602 | + |
|
| 603 | + switch (strtolower($type)) { |
|
| 604 | + case 'today': |
|
| 605 | + return "CURDATE()"; |
|
| 606 | + case 'left': |
|
| 607 | + return "LEFT($all_strings)"; |
|
| 608 | + case 'date_format': |
|
| 609 | + if(empty($additional_parameters)) { |
|
| 610 | + return "DATE_FORMAT($string,'%Y-%m-%d')"; |
|
| 611 | + } else { |
|
| 612 | + $format = $additional_parameters[0]; |
|
| 613 | + if($format[0] != "'") { |
|
| 614 | + $format = $this->quoted($format); |
|
| 615 | + } |
|
| 616 | + return "DATE_FORMAT($string,$format)"; |
|
| 617 | + } |
|
| 618 | + case 'ifnull': |
|
| 619 | + if(empty($additional_parameters) && !strstr($all_strings, ",")) { |
|
| 620 | + $all_strings .= ",''"; |
|
| 621 | + } |
|
| 622 | + return "IFNULL($all_strings)"; |
|
| 623 | + case 'concat': |
|
| 624 | + return "CONCAT($all_strings)"; |
|
| 625 | + case 'quarter': |
|
| 626 | + return "QUARTER($string)"; |
|
| 627 | + case "length": |
|
| 628 | + return "LENGTH($string)"; |
|
| 629 | + case 'month': |
|
| 630 | + return "MONTH($string)"; |
|
| 631 | + case 'add_date': |
|
| 632 | + return "DATE_ADD($string, INTERVAL {$additional_parameters[0]} {$additional_parameters[1]})"; |
|
| 633 | + case 'add_time': |
|
| 634 | + return "DATE_ADD($string, INTERVAL + CONCAT({$additional_parameters[0]}, ':', {$additional_parameters[1]}) HOUR_MINUTE)"; |
|
| 635 | 635 | case 'add_tz_offset' : |
| 636 | 636 | $getUserUTCOffset = $GLOBALS['timedate']->getUserUTCOffset(); |
| 637 | 637 | $operation = $getUserUTCOffset < 0 ? '-' : '+'; |
| 638 | 638 | return $string . ' ' . $operation . ' INTERVAL ' . abs($getUserUTCOffset) . ' MINUTE'; |
| 639 | 639 | case 'avg': |
| 640 | 640 | return "avg($string)"; |
| 641 | - } |
|
| 642 | - |
|
| 643 | - return $string; |
|
| 644 | - } |
|
| 645 | - |
|
| 646 | - /** |
|
| 647 | - * (non-PHPdoc) |
|
| 648 | - * @see DBManager::fromConvert() |
|
| 649 | - */ |
|
| 650 | - public function fromConvert($string, $type) |
|
| 651 | - { |
|
| 652 | - return $string; |
|
| 653 | - } |
|
| 654 | - |
|
| 655 | - /** |
|
| 656 | - * Returns the name of the engine to use or null if we are to use the default |
|
| 657 | - * |
|
| 658 | - * @param object $bean SugarBean instance |
|
| 659 | - * @return string |
|
| 660 | - */ |
|
| 661 | - protected function getEngine($bean) |
|
| 662 | - { |
|
| 663 | - global $dictionary; |
|
| 664 | - $engine = null; |
|
| 665 | - if (isset($dictionary[$bean->getObjectName()]['engine'])) { |
|
| 666 | - $engine = $dictionary[$bean->getObjectName()]['engine']; |
|
| 667 | - } |
|
| 668 | - return $engine; |
|
| 669 | - } |
|
| 670 | - |
|
| 671 | - /** |
|
| 672 | - * Returns true if the engine given is enabled in the backend |
|
| 673 | - * |
|
| 674 | - * @param string $engine |
|
| 675 | - * @return bool |
|
| 676 | - */ |
|
| 677 | - protected function isEngineEnabled($engine) |
|
| 678 | - { |
|
| 679 | - if(!is_string($engine)) return false; |
|
| 680 | - |
|
| 681 | - $engine = strtoupper($engine); |
|
| 682 | - |
|
| 683 | - $r = $this->query("SHOW ENGINES"); |
|
| 684 | - |
|
| 685 | - while ( $row = $this->fetchByAssoc($r) ) |
|
| 686 | - if ( strtoupper($row['Engine']) == $engine ) |
|
| 687 | - return ($row['Support']=='YES' || $row['Support']=='DEFAULT'); |
|
| 688 | - |
|
| 689 | - return false; |
|
| 690 | - } |
|
| 691 | - |
|
| 692 | - /** |
|
| 693 | - * @see DBManager::createTableSQL() |
|
| 694 | - */ |
|
| 695 | - public function createTableSQL(SugarBean $bean) |
|
| 696 | - { |
|
| 697 | - $tablename = $bean->getTableName(); |
|
| 698 | - $fieldDefs = $bean->getFieldDefinitions(); |
|
| 699 | - $indices = $bean->getIndices(); |
|
| 700 | - $engine = $this->getEngine($bean); |
|
| 701 | - return $this->createTableSQLParams($tablename, $fieldDefs, $indices, $engine); |
|
| 702 | - } |
|
| 703 | - |
|
| 704 | - /** |
|
| 705 | - * Generates sql for create table statement for a bean. |
|
| 706 | - * |
|
| 707 | - * @param string $tablename |
|
| 708 | - * @param array $fieldDefs |
|
| 709 | - * @param array $indices |
|
| 710 | - * @param string $engine optional, MySQL engine to use |
|
| 711 | - * @return string SQL Create Table statement |
|
| 712 | - */ |
|
| 713 | - public function createTableSQLParams($tablename, $fieldDefs, $indices, $engine = null) |
|
| 714 | - { |
|
| 715 | - if ( empty($engine) && isset($fieldDefs['engine'])) |
|
| 716 | - $engine = $fieldDefs['engine']; |
|
| 717 | - if ( !$this->isEngineEnabled($engine) ) |
|
| 718 | - $engine = ''; |
|
| 719 | - |
|
| 720 | - $columns = $this->columnSQLRep($fieldDefs, false, $tablename); |
|
| 721 | - if (empty($columns)) |
|
| 722 | - return false; |
|
| 723 | - |
|
| 724 | - $keys = $this->keysSQL($indices); |
|
| 725 | - if (!empty($keys)) |
|
| 726 | - $keys = ",$keys"; |
|
| 727 | - |
|
| 728 | - // cn: bug 9873 - module tables do not get created in utf8 with assoc collation |
|
| 729 | - $collation = $this->getOption('collation'); |
|
| 730 | - if(empty($collation)) { |
|
| 731 | - $collation = 'utf8_general_ci'; |
|
| 732 | - } |
|
| 733 | - $sql = "CREATE TABLE $tablename ($columns $keys) CHARACTER SET utf8 COLLATE $collation"; |
|
| 734 | - |
|
| 735 | - if (!empty($engine)) |
|
| 736 | - $sql.= " ENGINE=$engine"; |
|
| 737 | - |
|
| 738 | - return $sql; |
|
| 739 | - } |
|
| 641 | + } |
|
| 642 | + |
|
| 643 | + return $string; |
|
| 644 | + } |
|
| 645 | + |
|
| 646 | + /** |
|
| 647 | + * (non-PHPdoc) |
|
| 648 | + * @see DBManager::fromConvert() |
|
| 649 | + */ |
|
| 650 | + public function fromConvert($string, $type) |
|
| 651 | + { |
|
| 652 | + return $string; |
|
| 653 | + } |
|
| 654 | + |
|
| 655 | + /** |
|
| 656 | + * Returns the name of the engine to use or null if we are to use the default |
|
| 657 | + * |
|
| 658 | + * @param object $bean SugarBean instance |
|
| 659 | + * @return string |
|
| 660 | + */ |
|
| 661 | + protected function getEngine($bean) |
|
| 662 | + { |
|
| 663 | + global $dictionary; |
|
| 664 | + $engine = null; |
|
| 665 | + if (isset($dictionary[$bean->getObjectName()]['engine'])) { |
|
| 666 | + $engine = $dictionary[$bean->getObjectName()]['engine']; |
|
| 667 | + } |
|
| 668 | + return $engine; |
|
| 669 | + } |
|
| 670 | + |
|
| 671 | + /** |
|
| 672 | + * Returns true if the engine given is enabled in the backend |
|
| 673 | + * |
|
| 674 | + * @param string $engine |
|
| 675 | + * @return bool |
|
| 676 | + */ |
|
| 677 | + protected function isEngineEnabled($engine) |
|
| 678 | + { |
|
| 679 | + if(!is_string($engine)) return false; |
|
| 680 | + |
|
| 681 | + $engine = strtoupper($engine); |
|
| 682 | + |
|
| 683 | + $r = $this->query("SHOW ENGINES"); |
|
| 684 | + |
|
| 685 | + while ( $row = $this->fetchByAssoc($r) ) |
|
| 686 | + if ( strtoupper($row['Engine']) == $engine ) |
|
| 687 | + return ($row['Support']=='YES' || $row['Support']=='DEFAULT'); |
|
| 688 | + |
|
| 689 | + return false; |
|
| 690 | + } |
|
| 691 | + |
|
| 692 | + /** |
|
| 693 | + * @see DBManager::createTableSQL() |
|
| 694 | + */ |
|
| 695 | + public function createTableSQL(SugarBean $bean) |
|
| 696 | + { |
|
| 697 | + $tablename = $bean->getTableName(); |
|
| 698 | + $fieldDefs = $bean->getFieldDefinitions(); |
|
| 699 | + $indices = $bean->getIndices(); |
|
| 700 | + $engine = $this->getEngine($bean); |
|
| 701 | + return $this->createTableSQLParams($tablename, $fieldDefs, $indices, $engine); |
|
| 702 | + } |
|
| 703 | + |
|
| 704 | + /** |
|
| 705 | + * Generates sql for create table statement for a bean. |
|
| 706 | + * |
|
| 707 | + * @param string $tablename |
|
| 708 | + * @param array $fieldDefs |
|
| 709 | + * @param array $indices |
|
| 710 | + * @param string $engine optional, MySQL engine to use |
|
| 711 | + * @return string SQL Create Table statement |
|
| 712 | + */ |
|
| 713 | + public function createTableSQLParams($tablename, $fieldDefs, $indices, $engine = null) |
|
| 714 | + { |
|
| 715 | + if ( empty($engine) && isset($fieldDefs['engine'])) |
|
| 716 | + $engine = $fieldDefs['engine']; |
|
| 717 | + if ( !$this->isEngineEnabled($engine) ) |
|
| 718 | + $engine = ''; |
|
| 719 | + |
|
| 720 | + $columns = $this->columnSQLRep($fieldDefs, false, $tablename); |
|
| 721 | + if (empty($columns)) |
|
| 722 | + return false; |
|
| 723 | + |
|
| 724 | + $keys = $this->keysSQL($indices); |
|
| 725 | + if (!empty($keys)) |
|
| 726 | + $keys = ",$keys"; |
|
| 727 | + |
|
| 728 | + // cn: bug 9873 - module tables do not get created in utf8 with assoc collation |
|
| 729 | + $collation = $this->getOption('collation'); |
|
| 730 | + if(empty($collation)) { |
|
| 731 | + $collation = 'utf8_general_ci'; |
|
| 732 | + } |
|
| 733 | + $sql = "CREATE TABLE $tablename ($columns $keys) CHARACTER SET utf8 COLLATE $collation"; |
|
| 734 | + |
|
| 735 | + if (!empty($engine)) |
|
| 736 | + $sql.= " ENGINE=$engine"; |
|
| 737 | + |
|
| 738 | + return $sql; |
|
| 739 | + } |
|
| 740 | 740 | |
| 741 | 741 | /** |
| 742 | 742 | * Does this type represent text (i.e., non-varchar) value? |
@@ -748,745 +748,745 @@ discard block |
||
| 748 | 748 | return in_array($type, array('blob','text','longblob', 'longtext')); |
| 749 | 749 | } |
| 750 | 750 | |
| 751 | - /** |
|
| 752 | - * @see DBManager::oneColumnSQLRep() |
|
| 753 | - */ |
|
| 754 | - protected function oneColumnSQLRep($fieldDef, $ignoreRequired = false, $table = '', $return_as_array = false) |
|
| 755 | - { |
|
| 756 | - // always return as array for post-processing |
|
| 757 | - $ref = parent::oneColumnSQLRep($fieldDef, $ignoreRequired, $table, true); |
|
| 751 | + /** |
|
| 752 | + * @see DBManager::oneColumnSQLRep() |
|
| 753 | + */ |
|
| 754 | + protected function oneColumnSQLRep($fieldDef, $ignoreRequired = false, $table = '', $return_as_array = false) |
|
| 755 | + { |
|
| 756 | + // always return as array for post-processing |
|
| 757 | + $ref = parent::oneColumnSQLRep($fieldDef, $ignoreRequired, $table, true); |
|
| 758 | 758 | |
| 759 | - if ( $ref['colType'] == 'int' && !empty($fieldDef['len']) ) { |
|
| 760 | - $ref['colType'] .= "(".$fieldDef['len'].")"; |
|
| 761 | - } |
|
| 759 | + if ( $ref['colType'] == 'int' && !empty($fieldDef['len']) ) { |
|
| 760 | + $ref['colType'] .= "(".$fieldDef['len'].")"; |
|
| 761 | + } |
|
| 762 | 762 | |
| 763 | - // bug 22338 - don't set a default value on text or blob fields |
|
| 764 | - if ( isset($ref['default']) && |
|
| 763 | + // bug 22338 - don't set a default value on text or blob fields |
|
| 764 | + if ( isset($ref['default']) && |
|
| 765 | 765 | in_array($ref['colBaseType'], array('text', 'blob', 'longtext', 'longblob'))) |
| 766 | - $ref['default'] = ''; |
|
| 767 | - |
|
| 768 | - if ( $return_as_array ) |
|
| 769 | - return $ref; |
|
| 770 | - else |
|
| 771 | - return "{$ref['name']} {$ref['colType']} {$ref['default']} {$ref['required']} {$ref['auto_increment']}"; |
|
| 772 | - } |
|
| 773 | - |
|
| 774 | - /** |
|
| 775 | - * @see DBManager::changeColumnSQL() |
|
| 776 | - */ |
|
| 777 | - protected function changeColumnSQL($tablename, $fieldDefs, $action, $ignoreRequired = false) |
|
| 778 | - { |
|
| 779 | - $columns = array(); |
|
| 780 | - if ($this->isFieldArray($fieldDefs)){ |
|
| 781 | - foreach ($fieldDefs as $def){ |
|
| 782 | - if ($action == 'drop') |
|
| 783 | - $columns[] = $def['name']; |
|
| 784 | - else |
|
| 785 | - $columns[] = $this->oneColumnSQLRep($def, $ignoreRequired); |
|
| 786 | - } |
|
| 787 | - } else { |
|
| 788 | - if ($action == 'drop') |
|
| 789 | - $columns[] = $fieldDefs['name']; |
|
| 790 | - else |
|
| 791 | - $columns[] = $this->oneColumnSQLRep($fieldDefs); |
|
| 792 | - } |
|
| 793 | - |
|
| 794 | - return "ALTER TABLE $tablename $action COLUMN ".implode(",$action column ", $columns); |
|
| 795 | - } |
|
| 796 | - |
|
| 797 | - /** |
|
| 798 | - * Generates SQL for key specification inside CREATE TABLE statement |
|
| 799 | - * |
|
| 800 | - * The passes array is an array of field definitions or a field definition |
|
| 801 | - * itself. The keys generated will be either primary, foreign, unique, index |
|
| 802 | - * or none at all depending on the setting of the "key" parameter of a field definition |
|
| 803 | - * |
|
| 804 | - * @param array $indices |
|
| 805 | - * @param bool $alter_table |
|
| 806 | - * @param string $alter_action |
|
| 807 | - * @return string SQL Statement |
|
| 808 | - */ |
|
| 809 | - protected function keysSQL($indices, $alter_table = false, $alter_action = '') |
|
| 810 | - { |
|
| 811 | - // check if the passed value is an array of fields. |
|
| 812 | - // if not, convert it into an array |
|
| 813 | - if (!$this->isFieldArray($indices)) |
|
| 814 | - $indices[] = $indices; |
|
| 815 | - |
|
| 816 | - $columns = array(); |
|
| 817 | - foreach ($indices as $index) { |
|
| 818 | - if(!empty($index['db']) && $index['db'] != $this->dbType) |
|
| 819 | - continue; |
|
| 820 | - if (isset($index['source']) && $index['source'] != 'db') |
|
| 821 | - continue; |
|
| 822 | - |
|
| 823 | - $type = $index['type']; |
|
| 824 | - $name = $index['name']; |
|
| 825 | - |
|
| 826 | - if (is_array($index['fields'])) |
|
| 827 | - $fields = implode(", ", $index['fields']); |
|
| 828 | - else |
|
| 829 | - $fields = $index['fields']; |
|
| 830 | - |
|
| 831 | - switch ($type) { |
|
| 832 | - case 'unique': |
|
| 833 | - $columns[] = " UNIQUE $name ($fields)"; |
|
| 834 | - break; |
|
| 835 | - case 'primary': |
|
| 836 | - $columns[] = " PRIMARY KEY ($fields)"; |
|
| 837 | - break; |
|
| 838 | - case 'index': |
|
| 839 | - case 'foreign': |
|
| 840 | - case 'clustered': |
|
| 841 | - case 'alternate_key': |
|
| 842 | - /** |
|
| 843 | - * @todo here it is assumed that the primary key of the foreign |
|
| 844 | - * table will always be named 'id'. It must be noted though |
|
| 845 | - * that this can easily be fixed by referring to db dictionary |
|
| 846 | - * to find the correct primary field name |
|
| 847 | - */ |
|
| 848 | - if ( $alter_table ) |
|
| 849 | - $columns[] = " INDEX $name ($fields)"; |
|
| 850 | - else |
|
| 851 | - $columns[] = " KEY $name ($fields)"; |
|
| 852 | - break; |
|
| 853 | - case 'fulltext': |
|
| 854 | - if ($this->full_text_indexing_installed()) |
|
| 855 | - $columns[] = " FULLTEXT ($fields)"; |
|
| 856 | - else |
|
| 857 | - $GLOBALS['log']->debug('MYISAM engine is not available/enabled, full-text indexes will be skipped. Skipping:',$name); |
|
| 858 | - break; |
|
| 859 | - } |
|
| 860 | - } |
|
| 861 | - $columns = implode(", $alter_action ", $columns); |
|
| 862 | - if(!empty($alter_action)){ |
|
| 863 | - $columns = $alter_action . ' '. $columns; |
|
| 864 | - } |
|
| 865 | - return $columns; |
|
| 866 | - } |
|
| 867 | - |
|
| 868 | - /** |
|
| 869 | - * @see DBManager::setAutoIncrement() |
|
| 870 | - */ |
|
| 871 | - protected function setAutoIncrement($table, $field_name) |
|
| 872 | - { |
|
| 873 | - return "auto_increment"; |
|
| 874 | - } |
|
| 875 | - |
|
| 876 | - /** |
|
| 877 | - * Sets the next auto-increment value of a column to a specific value. |
|
| 878 | - * |
|
| 879 | - * @param string $table tablename |
|
| 880 | - * @param string $field_name |
|
| 881 | - */ |
|
| 882 | - public function setAutoIncrementStart($table, $field_name, $start_value) |
|
| 883 | - { |
|
| 884 | - $start_value = (int)$start_value; |
|
| 885 | - return $this->query( "ALTER TABLE $table AUTO_INCREMENT = $start_value;"); |
|
| 886 | - } |
|
| 887 | - |
|
| 888 | - /** |
|
| 889 | - * Returns the next value for an auto increment |
|
| 890 | - * |
|
| 891 | - * @param string $table tablename |
|
| 892 | - * @param string $field_name |
|
| 893 | - * @return string |
|
| 894 | - */ |
|
| 895 | - public function getAutoIncrement($table, $field_name) |
|
| 896 | - { |
|
| 897 | - $result = $this->query("SHOW TABLE STATUS LIKE '$table'"); |
|
| 898 | - $row = $this->fetchByAssoc($result); |
|
| 899 | - if (!empty($row['Auto_increment'])) |
|
| 900 | - return $row['Auto_increment']; |
|
| 901 | - |
|
| 902 | - return ""; |
|
| 903 | - } |
|
| 904 | - |
|
| 905 | - /** |
|
| 906 | - * @see DBManager::get_indices() |
|
| 907 | - */ |
|
| 908 | - public function get_indices($tablename) |
|
| 909 | - { |
|
| 910 | - //find all unique indexes and primary keys. |
|
| 911 | - $result = $this->query("SHOW INDEX FROM $tablename"); |
|
| 912 | - |
|
| 913 | - $indices = array(); |
|
| 914 | - while (($row=$this->fetchByAssoc($result)) !=null) { |
|
| 915 | - $index_type='index'; |
|
| 916 | - if ($row['Key_name'] =='PRIMARY') { |
|
| 917 | - $index_type='primary'; |
|
| 918 | - } |
|
| 919 | - elseif ( $row['Non_unique'] == '0' ) { |
|
| 920 | - $index_type='unique'; |
|
| 921 | - } |
|
| 922 | - $name = strtolower($row['Key_name']); |
|
| 923 | - $indices[$name]['name']=$name; |
|
| 924 | - $indices[$name]['type']=$index_type; |
|
| 925 | - $indices[$name]['fields'][]=strtolower($row['Column_name']); |
|
| 926 | - } |
|
| 927 | - return $indices; |
|
| 928 | - } |
|
| 929 | - |
|
| 930 | - /** |
|
| 931 | - * @see DBManager::add_drop_constraint() |
|
| 932 | - */ |
|
| 933 | - public function add_drop_constraint($table, $definition, $drop = false) |
|
| 934 | - { |
|
| 935 | - $type = $definition['type']; |
|
| 936 | - $fields = implode(',',$definition['fields']); |
|
| 937 | - $name = $definition['name']; |
|
| 938 | - $sql = ''; |
|
| 939 | - |
|
| 940 | - switch ($type){ |
|
| 941 | - // generic indices |
|
| 942 | - case 'index': |
|
| 943 | - case 'alternate_key': |
|
| 944 | - case 'clustered': |
|
| 945 | - if ($drop) |
|
| 946 | - $sql = "ALTER TABLE {$table} DROP INDEX {$name} "; |
|
| 947 | - else |
|
| 948 | - $sql = "ALTER TABLE {$table} ADD INDEX {$name} ({$fields})"; |
|
| 949 | - break; |
|
| 950 | - // constraints as indices |
|
| 951 | - case 'unique': |
|
| 952 | - if ($drop) |
|
| 953 | - $sql = "ALTER TABLE {$table} DROP INDEX $name"; |
|
| 954 | - else |
|
| 955 | - $sql = "ALTER TABLE {$table} ADD CONSTRAINT UNIQUE {$name} ({$fields})"; |
|
| 956 | - break; |
|
| 957 | - case 'primary': |
|
| 958 | - if ($drop) |
|
| 959 | - $sql = "ALTER TABLE {$table} DROP PRIMARY KEY"; |
|
| 960 | - else |
|
| 961 | - $sql = "ALTER TABLE {$table} ADD CONSTRAINT PRIMARY KEY ({$fields})"; |
|
| 962 | - break; |
|
| 963 | - case 'foreign': |
|
| 964 | - if ($drop) |
|
| 965 | - $sql = "ALTER TABLE {$table} DROP FOREIGN KEY ({$fields})"; |
|
| 966 | - else |
|
| 967 | - $sql = "ALTER TABLE {$table} ADD CONSTRAINT FOREIGN KEY {$name} ({$fields}) REFERENCES {$definition['foreignTable']}({$definition['foreignField']})"; |
|
| 968 | - break; |
|
| 969 | - } |
|
| 970 | - return $sql; |
|
| 971 | - } |
|
| 972 | - |
|
| 973 | - /** |
|
| 974 | - * Runs a query and returns a single row |
|
| 975 | - * |
|
| 976 | - * @param string $sql SQL Statement to execute |
|
| 977 | - * @param bool $dieOnError True if we want to call die if the query returns errors |
|
| 978 | - * @param string $msg Message to log if error occurs |
|
| 979 | - * @param bool $suppress Message to log if error occurs |
|
| 980 | - * @return array single row from the query |
|
| 981 | - */ |
|
| 982 | - public function fetchOne($sql, $dieOnError = false, $msg = '', $suppress = false) |
|
| 983 | - { |
|
| 984 | - if(stripos($sql, ' LIMIT ') === false) { |
|
| 985 | - // little optimization to just fetch one row |
|
| 986 | - $sql .= " LIMIT 0,1"; |
|
| 987 | - } |
|
| 988 | - return parent::fetchOne($sql, $dieOnError, $msg, $suppress); |
|
| 989 | - } |
|
| 990 | - |
|
| 991 | - /** |
|
| 992 | - * @see DBManager::full_text_indexing_installed() |
|
| 993 | - */ |
|
| 994 | - public function full_text_indexing_installed($dbname = null) |
|
| 995 | - { |
|
| 996 | - return $this->isEngineEnabled('MyISAM'); |
|
| 997 | - } |
|
| 998 | - |
|
| 999 | - /** |
|
| 1000 | - * @see DBManager::massageFieldDef() |
|
| 1001 | - */ |
|
| 1002 | - public function massageFieldDef(&$fieldDef, $tablename) |
|
| 1003 | - { |
|
| 1004 | - parent::massageFieldDef($fieldDef,$tablename); |
|
| 1005 | - |
|
| 1006 | - if ( isset($fieldDef['default']) && |
|
| 1007 | - ($fieldDef['dbType'] == 'text' |
|
| 1008 | - || $fieldDef['dbType'] == 'blob' |
|
| 1009 | - || $fieldDef['dbType'] == 'longtext' |
|
| 1010 | - || $fieldDef['dbType'] == 'longblob' )) |
|
| 1011 | - unset($fieldDef['default']); |
|
| 1012 | - if ($fieldDef['dbType'] == 'uint') |
|
| 1013 | - $fieldDef['len'] = '10'; |
|
| 1014 | - if ($fieldDef['dbType'] == 'ulong') |
|
| 1015 | - $fieldDef['len'] = '20'; |
|
| 1016 | - if ($fieldDef['dbType'] == 'bool') |
|
| 1017 | - $fieldDef['type'] = 'tinyint'; |
|
| 1018 | - if ($fieldDef['dbType'] == 'bool' && empty($fieldDef['default']) ) |
|
| 1019 | - $fieldDef['default'] = '0'; |
|
| 1020 | - if (($fieldDef['dbType'] == 'varchar' || $fieldDef['dbType'] == 'enum') && empty($fieldDef['len']) ) |
|
| 1021 | - $fieldDef['len'] = '255'; |
|
| 1022 | - if ($fieldDef['dbType'] == 'uint') |
|
| 1023 | - $fieldDef['len'] = '10'; |
|
| 1024 | - if ($fieldDef['dbType'] == 'int' && empty($fieldDef['len']) ) |
|
| 1025 | - $fieldDef['len'] = '11'; |
|
| 1026 | - |
|
| 1027 | - if($fieldDef['dbType'] == 'decimal') { |
|
| 1028 | - if(isset($fieldDef['len'])) { |
|
| 1029 | - if(strstr($fieldDef['len'], ",") === false) { |
|
| 1030 | - $fieldDef['len'] .= ",0"; |
|
| 1031 | - } |
|
| 1032 | - } else { |
|
| 1033 | - $fieldDef['len'] = '10,0'; |
|
| 1034 | - } |
|
| 1035 | - } |
|
| 1036 | - } |
|
| 1037 | - |
|
| 1038 | - /** |
|
| 1039 | - * Generates SQL for dropping a table. |
|
| 1040 | - * |
|
| 1041 | - * @param string $name table name |
|
| 1042 | - * @return string SQL statement |
|
| 1043 | - */ |
|
| 1044 | - public function dropTableNameSQL($name) |
|
| 1045 | - { |
|
| 1046 | - return "DROP TABLE IF EXISTS ".$name; |
|
| 1047 | - } |
|
| 1048 | - |
|
| 1049 | - public function dropIndexes($tablename, $indexes, $execute = true) |
|
| 1050 | - { |
|
| 1051 | - $sql = array(); |
|
| 1052 | - foreach ($indexes as $index) { |
|
| 1053 | - $name =$index['name']; |
|
| 1054 | - if($execute) { |
|
| 1055 | - unset(self::$index_descriptions[$tablename][$name]); |
|
| 1056 | - } |
|
| 1057 | - if ($index['type'] == 'primary') { |
|
| 1058 | - $sql[] = 'DROP PRIMARY KEY'; |
|
| 1059 | - } else { |
|
| 1060 | - $sql[] = "DROP INDEX $name"; |
|
| 1061 | - } |
|
| 1062 | - } |
|
| 1063 | - if (!empty($sql)) { |
|
| 766 | + $ref['default'] = ''; |
|
| 767 | + |
|
| 768 | + if ( $return_as_array ) |
|
| 769 | + return $ref; |
|
| 770 | + else |
|
| 771 | + return "{$ref['name']} {$ref['colType']} {$ref['default']} {$ref['required']} {$ref['auto_increment']}"; |
|
| 772 | + } |
|
| 773 | + |
|
| 774 | + /** |
|
| 775 | + * @see DBManager::changeColumnSQL() |
|
| 776 | + */ |
|
| 777 | + protected function changeColumnSQL($tablename, $fieldDefs, $action, $ignoreRequired = false) |
|
| 778 | + { |
|
| 779 | + $columns = array(); |
|
| 780 | + if ($this->isFieldArray($fieldDefs)){ |
|
| 781 | + foreach ($fieldDefs as $def){ |
|
| 782 | + if ($action == 'drop') |
|
| 783 | + $columns[] = $def['name']; |
|
| 784 | + else |
|
| 785 | + $columns[] = $this->oneColumnSQLRep($def, $ignoreRequired); |
|
| 786 | + } |
|
| 787 | + } else { |
|
| 788 | + if ($action == 'drop') |
|
| 789 | + $columns[] = $fieldDefs['name']; |
|
| 790 | + else |
|
| 791 | + $columns[] = $this->oneColumnSQLRep($fieldDefs); |
|
| 792 | + } |
|
| 793 | + |
|
| 794 | + return "ALTER TABLE $tablename $action COLUMN ".implode(",$action column ", $columns); |
|
| 795 | + } |
|
| 796 | + |
|
| 797 | + /** |
|
| 798 | + * Generates SQL for key specification inside CREATE TABLE statement |
|
| 799 | + * |
|
| 800 | + * The passes array is an array of field definitions or a field definition |
|
| 801 | + * itself. The keys generated will be either primary, foreign, unique, index |
|
| 802 | + * or none at all depending on the setting of the "key" parameter of a field definition |
|
| 803 | + * |
|
| 804 | + * @param array $indices |
|
| 805 | + * @param bool $alter_table |
|
| 806 | + * @param string $alter_action |
|
| 807 | + * @return string SQL Statement |
|
| 808 | + */ |
|
| 809 | + protected function keysSQL($indices, $alter_table = false, $alter_action = '') |
|
| 810 | + { |
|
| 811 | + // check if the passed value is an array of fields. |
|
| 812 | + // if not, convert it into an array |
|
| 813 | + if (!$this->isFieldArray($indices)) |
|
| 814 | + $indices[] = $indices; |
|
| 815 | + |
|
| 816 | + $columns = array(); |
|
| 817 | + foreach ($indices as $index) { |
|
| 818 | + if(!empty($index['db']) && $index['db'] != $this->dbType) |
|
| 819 | + continue; |
|
| 820 | + if (isset($index['source']) && $index['source'] != 'db') |
|
| 821 | + continue; |
|
| 822 | + |
|
| 823 | + $type = $index['type']; |
|
| 824 | + $name = $index['name']; |
|
| 825 | + |
|
| 826 | + if (is_array($index['fields'])) |
|
| 827 | + $fields = implode(", ", $index['fields']); |
|
| 828 | + else |
|
| 829 | + $fields = $index['fields']; |
|
| 830 | + |
|
| 831 | + switch ($type) { |
|
| 832 | + case 'unique': |
|
| 833 | + $columns[] = " UNIQUE $name ($fields)"; |
|
| 834 | + break; |
|
| 835 | + case 'primary': |
|
| 836 | + $columns[] = " PRIMARY KEY ($fields)"; |
|
| 837 | + break; |
|
| 838 | + case 'index': |
|
| 839 | + case 'foreign': |
|
| 840 | + case 'clustered': |
|
| 841 | + case 'alternate_key': |
|
| 842 | + /** |
|
| 843 | + * @todo here it is assumed that the primary key of the foreign |
|
| 844 | + * table will always be named 'id'. It must be noted though |
|
| 845 | + * that this can easily be fixed by referring to db dictionary |
|
| 846 | + * to find the correct primary field name |
|
| 847 | + */ |
|
| 848 | + if ( $alter_table ) |
|
| 849 | + $columns[] = " INDEX $name ($fields)"; |
|
| 850 | + else |
|
| 851 | + $columns[] = " KEY $name ($fields)"; |
|
| 852 | + break; |
|
| 853 | + case 'fulltext': |
|
| 854 | + if ($this->full_text_indexing_installed()) |
|
| 855 | + $columns[] = " FULLTEXT ($fields)"; |
|
| 856 | + else |
|
| 857 | + $GLOBALS['log']->debug('MYISAM engine is not available/enabled, full-text indexes will be skipped. Skipping:',$name); |
|
| 858 | + break; |
|
| 859 | + } |
|
| 860 | + } |
|
| 861 | + $columns = implode(", $alter_action ", $columns); |
|
| 862 | + if(!empty($alter_action)){ |
|
| 863 | + $columns = $alter_action . ' '. $columns; |
|
| 864 | + } |
|
| 865 | + return $columns; |
|
| 866 | + } |
|
| 867 | + |
|
| 868 | + /** |
|
| 869 | + * @see DBManager::setAutoIncrement() |
|
| 870 | + */ |
|
| 871 | + protected function setAutoIncrement($table, $field_name) |
|
| 872 | + { |
|
| 873 | + return "auto_increment"; |
|
| 874 | + } |
|
| 875 | + |
|
| 876 | + /** |
|
| 877 | + * Sets the next auto-increment value of a column to a specific value. |
|
| 878 | + * |
|
| 879 | + * @param string $table tablename |
|
| 880 | + * @param string $field_name |
|
| 881 | + */ |
|
| 882 | + public function setAutoIncrementStart($table, $field_name, $start_value) |
|
| 883 | + { |
|
| 884 | + $start_value = (int)$start_value; |
|
| 885 | + return $this->query( "ALTER TABLE $table AUTO_INCREMENT = $start_value;"); |
|
| 886 | + } |
|
| 887 | + |
|
| 888 | + /** |
|
| 889 | + * Returns the next value for an auto increment |
|
| 890 | + * |
|
| 891 | + * @param string $table tablename |
|
| 892 | + * @param string $field_name |
|
| 893 | + * @return string |
|
| 894 | + */ |
|
| 895 | + public function getAutoIncrement($table, $field_name) |
|
| 896 | + { |
|
| 897 | + $result = $this->query("SHOW TABLE STATUS LIKE '$table'"); |
|
| 898 | + $row = $this->fetchByAssoc($result); |
|
| 899 | + if (!empty($row['Auto_increment'])) |
|
| 900 | + return $row['Auto_increment']; |
|
| 901 | + |
|
| 902 | + return ""; |
|
| 903 | + } |
|
| 904 | + |
|
| 905 | + /** |
|
| 906 | + * @see DBManager::get_indices() |
|
| 907 | + */ |
|
| 908 | + public function get_indices($tablename) |
|
| 909 | + { |
|
| 910 | + //find all unique indexes and primary keys. |
|
| 911 | + $result = $this->query("SHOW INDEX FROM $tablename"); |
|
| 912 | + |
|
| 913 | + $indices = array(); |
|
| 914 | + while (($row=$this->fetchByAssoc($result)) !=null) { |
|
| 915 | + $index_type='index'; |
|
| 916 | + if ($row['Key_name'] =='PRIMARY') { |
|
| 917 | + $index_type='primary'; |
|
| 918 | + } |
|
| 919 | + elseif ( $row['Non_unique'] == '0' ) { |
|
| 920 | + $index_type='unique'; |
|
| 921 | + } |
|
| 922 | + $name = strtolower($row['Key_name']); |
|
| 923 | + $indices[$name]['name']=$name; |
|
| 924 | + $indices[$name]['type']=$index_type; |
|
| 925 | + $indices[$name]['fields'][]=strtolower($row['Column_name']); |
|
| 926 | + } |
|
| 927 | + return $indices; |
|
| 928 | + } |
|
| 929 | + |
|
| 930 | + /** |
|
| 931 | + * @see DBManager::add_drop_constraint() |
|
| 932 | + */ |
|
| 933 | + public function add_drop_constraint($table, $definition, $drop = false) |
|
| 934 | + { |
|
| 935 | + $type = $definition['type']; |
|
| 936 | + $fields = implode(',',$definition['fields']); |
|
| 937 | + $name = $definition['name']; |
|
| 938 | + $sql = ''; |
|
| 939 | + |
|
| 940 | + switch ($type){ |
|
| 941 | + // generic indices |
|
| 942 | + case 'index': |
|
| 943 | + case 'alternate_key': |
|
| 944 | + case 'clustered': |
|
| 945 | + if ($drop) |
|
| 946 | + $sql = "ALTER TABLE {$table} DROP INDEX {$name} "; |
|
| 947 | + else |
|
| 948 | + $sql = "ALTER TABLE {$table} ADD INDEX {$name} ({$fields})"; |
|
| 949 | + break; |
|
| 950 | + // constraints as indices |
|
| 951 | + case 'unique': |
|
| 952 | + if ($drop) |
|
| 953 | + $sql = "ALTER TABLE {$table} DROP INDEX $name"; |
|
| 954 | + else |
|
| 955 | + $sql = "ALTER TABLE {$table} ADD CONSTRAINT UNIQUE {$name} ({$fields})"; |
|
| 956 | + break; |
|
| 957 | + case 'primary': |
|
| 958 | + if ($drop) |
|
| 959 | + $sql = "ALTER TABLE {$table} DROP PRIMARY KEY"; |
|
| 960 | + else |
|
| 961 | + $sql = "ALTER TABLE {$table} ADD CONSTRAINT PRIMARY KEY ({$fields})"; |
|
| 962 | + break; |
|
| 963 | + case 'foreign': |
|
| 964 | + if ($drop) |
|
| 965 | + $sql = "ALTER TABLE {$table} DROP FOREIGN KEY ({$fields})"; |
|
| 966 | + else |
|
| 967 | + $sql = "ALTER TABLE {$table} ADD CONSTRAINT FOREIGN KEY {$name} ({$fields}) REFERENCES {$definition['foreignTable']}({$definition['foreignField']})"; |
|
| 968 | + break; |
|
| 969 | + } |
|
| 970 | + return $sql; |
|
| 971 | + } |
|
| 972 | + |
|
| 973 | + /** |
|
| 974 | + * Runs a query and returns a single row |
|
| 975 | + * |
|
| 976 | + * @param string $sql SQL Statement to execute |
|
| 977 | + * @param bool $dieOnError True if we want to call die if the query returns errors |
|
| 978 | + * @param string $msg Message to log if error occurs |
|
| 979 | + * @param bool $suppress Message to log if error occurs |
|
| 980 | + * @return array single row from the query |
|
| 981 | + */ |
|
| 982 | + public function fetchOne($sql, $dieOnError = false, $msg = '', $suppress = false) |
|
| 983 | + { |
|
| 984 | + if(stripos($sql, ' LIMIT ') === false) { |
|
| 985 | + // little optimization to just fetch one row |
|
| 986 | + $sql .= " LIMIT 0,1"; |
|
| 987 | + } |
|
| 988 | + return parent::fetchOne($sql, $dieOnError, $msg, $suppress); |
|
| 989 | + } |
|
| 990 | + |
|
| 991 | + /** |
|
| 992 | + * @see DBManager::full_text_indexing_installed() |
|
| 993 | + */ |
|
| 994 | + public function full_text_indexing_installed($dbname = null) |
|
| 995 | + { |
|
| 996 | + return $this->isEngineEnabled('MyISAM'); |
|
| 997 | + } |
|
| 998 | + |
|
| 999 | + /** |
|
| 1000 | + * @see DBManager::massageFieldDef() |
|
| 1001 | + */ |
|
| 1002 | + public function massageFieldDef(&$fieldDef, $tablename) |
|
| 1003 | + { |
|
| 1004 | + parent::massageFieldDef($fieldDef,$tablename); |
|
| 1005 | + |
|
| 1006 | + if ( isset($fieldDef['default']) && |
|
| 1007 | + ($fieldDef['dbType'] == 'text' |
|
| 1008 | + || $fieldDef['dbType'] == 'blob' |
|
| 1009 | + || $fieldDef['dbType'] == 'longtext' |
|
| 1010 | + || $fieldDef['dbType'] == 'longblob' )) |
|
| 1011 | + unset($fieldDef['default']); |
|
| 1012 | + if ($fieldDef['dbType'] == 'uint') |
|
| 1013 | + $fieldDef['len'] = '10'; |
|
| 1014 | + if ($fieldDef['dbType'] == 'ulong') |
|
| 1015 | + $fieldDef['len'] = '20'; |
|
| 1016 | + if ($fieldDef['dbType'] == 'bool') |
|
| 1017 | + $fieldDef['type'] = 'tinyint'; |
|
| 1018 | + if ($fieldDef['dbType'] == 'bool' && empty($fieldDef['default']) ) |
|
| 1019 | + $fieldDef['default'] = '0'; |
|
| 1020 | + if (($fieldDef['dbType'] == 'varchar' || $fieldDef['dbType'] == 'enum') && empty($fieldDef['len']) ) |
|
| 1021 | + $fieldDef['len'] = '255'; |
|
| 1022 | + if ($fieldDef['dbType'] == 'uint') |
|
| 1023 | + $fieldDef['len'] = '10'; |
|
| 1024 | + if ($fieldDef['dbType'] == 'int' && empty($fieldDef['len']) ) |
|
| 1025 | + $fieldDef['len'] = '11'; |
|
| 1026 | + |
|
| 1027 | + if($fieldDef['dbType'] == 'decimal') { |
|
| 1028 | + if(isset($fieldDef['len'])) { |
|
| 1029 | + if(strstr($fieldDef['len'], ",") === false) { |
|
| 1030 | + $fieldDef['len'] .= ",0"; |
|
| 1031 | + } |
|
| 1032 | + } else { |
|
| 1033 | + $fieldDef['len'] = '10,0'; |
|
| 1034 | + } |
|
| 1035 | + } |
|
| 1036 | + } |
|
| 1037 | + |
|
| 1038 | + /** |
|
| 1039 | + * Generates SQL for dropping a table. |
|
| 1040 | + * |
|
| 1041 | + * @param string $name table name |
|
| 1042 | + * @return string SQL statement |
|
| 1043 | + */ |
|
| 1044 | + public function dropTableNameSQL($name) |
|
| 1045 | + { |
|
| 1046 | + return "DROP TABLE IF EXISTS ".$name; |
|
| 1047 | + } |
|
| 1048 | + |
|
| 1049 | + public function dropIndexes($tablename, $indexes, $execute = true) |
|
| 1050 | + { |
|
| 1051 | + $sql = array(); |
|
| 1052 | + foreach ($indexes as $index) { |
|
| 1053 | + $name =$index['name']; |
|
| 1054 | + if($execute) { |
|
| 1055 | + unset(self::$index_descriptions[$tablename][$name]); |
|
| 1056 | + } |
|
| 1057 | + if ($index['type'] == 'primary') { |
|
| 1058 | + $sql[] = 'DROP PRIMARY KEY'; |
|
| 1059 | + } else { |
|
| 1060 | + $sql[] = "DROP INDEX $name"; |
|
| 1061 | + } |
|
| 1062 | + } |
|
| 1063 | + if (!empty($sql)) { |
|
| 1064 | 1064 | $sql = "ALTER TABLE $tablename " . join(",", $sql) . ";"; |
| 1065 | - if($execute) |
|
| 1066 | - $this->query($sql); |
|
| 1067 | - } else { |
|
| 1068 | - $sql = ''; |
|
| 1069 | - } |
|
| 1070 | - return $sql; |
|
| 1071 | - } |
|
| 1072 | - |
|
| 1073 | - /** |
|
| 1074 | - * List of available collation settings |
|
| 1075 | - * @return string |
|
| 1076 | - */ |
|
| 1077 | - public function getDefaultCollation() |
|
| 1078 | - { |
|
| 1079 | - return "utf8_general_ci"; |
|
| 1080 | - } |
|
| 1081 | - |
|
| 1082 | - /** |
|
| 1083 | - * List of available collation settings |
|
| 1084 | - * @return array |
|
| 1085 | - */ |
|
| 1086 | - public function getCollationList() |
|
| 1087 | - { |
|
| 1088 | - $q = "SHOW COLLATION LIKE 'utf8%'"; |
|
| 1089 | - $r = $this->query($q); |
|
| 1090 | - $res = array(); |
|
| 1091 | - while($a = $this->fetchByAssoc($r)) { |
|
| 1092 | - $res[] = $a['Collation']; |
|
| 1093 | - } |
|
| 1094 | - return $res; |
|
| 1095 | - } |
|
| 1096 | - |
|
| 1097 | - /** |
|
| 1098 | - * (non-PHPdoc) |
|
| 1099 | - * @see DBManager::renameColumnSQL() |
|
| 1100 | - */ |
|
| 1101 | - public function renameColumnSQL($tablename, $column, $newname) |
|
| 1102 | - { |
|
| 1103 | - $field = $this->describeField($column, $tablename); |
|
| 1104 | - $field['name'] = $newname; |
|
| 1105 | - return "ALTER TABLE $tablename CHANGE COLUMN $column ".$this->oneColumnSQLRep($field); |
|
| 1106 | - } |
|
| 1107 | - |
|
| 1108 | - public function emptyValue($type) |
|
| 1109 | - { |
|
| 1110 | - $ctype = $this->getColumnType($type); |
|
| 1111 | - if($ctype == "datetime") { |
|
| 1112 | - return 'NULL'; |
|
| 1113 | - } |
|
| 1114 | - if($ctype == "date") { |
|
| 1115 | - return 'NULL'; |
|
| 1116 | - } |
|
| 1117 | - if($ctype == "time") { |
|
| 1118 | - return 'NULL'; |
|
| 1119 | - } |
|
| 1120 | - return parent::emptyValue($type); |
|
| 1121 | - } |
|
| 1122 | - |
|
| 1123 | - /** |
|
| 1124 | - * (non-PHPdoc) |
|
| 1125 | - * @see DBManager::lastDbError() |
|
| 1126 | - */ |
|
| 1127 | - public function lastDbError() |
|
| 1128 | - { |
|
| 1129 | - if($this->database) { |
|
| 1130 | - if(mysql_errno($this->database)) { |
|
| 1131 | - return "MySQL error ".mysql_errno($this->database).": ".mysql_error($this->database); |
|
| 1132 | - } |
|
| 1133 | - } else { |
|
| 1134 | - $err = mysql_error(); |
|
| 1135 | - if($err) { |
|
| 1136 | - return $err; |
|
| 1137 | - } |
|
| 1138 | - } |
|
| 1065 | + if($execute) |
|
| 1066 | + $this->query($sql); |
|
| 1067 | + } else { |
|
| 1068 | + $sql = ''; |
|
| 1069 | + } |
|
| 1070 | + return $sql; |
|
| 1071 | + } |
|
| 1072 | + |
|
| 1073 | + /** |
|
| 1074 | + * List of available collation settings |
|
| 1075 | + * @return string |
|
| 1076 | + */ |
|
| 1077 | + public function getDefaultCollation() |
|
| 1078 | + { |
|
| 1079 | + return "utf8_general_ci"; |
|
| 1080 | + } |
|
| 1081 | + |
|
| 1082 | + /** |
|
| 1083 | + * List of available collation settings |
|
| 1084 | + * @return array |
|
| 1085 | + */ |
|
| 1086 | + public function getCollationList() |
|
| 1087 | + { |
|
| 1088 | + $q = "SHOW COLLATION LIKE 'utf8%'"; |
|
| 1089 | + $r = $this->query($q); |
|
| 1090 | + $res = array(); |
|
| 1091 | + while($a = $this->fetchByAssoc($r)) { |
|
| 1092 | + $res[] = $a['Collation']; |
|
| 1093 | + } |
|
| 1094 | + return $res; |
|
| 1095 | + } |
|
| 1096 | + |
|
| 1097 | + /** |
|
| 1098 | + * (non-PHPdoc) |
|
| 1099 | + * @see DBManager::renameColumnSQL() |
|
| 1100 | + */ |
|
| 1101 | + public function renameColumnSQL($tablename, $column, $newname) |
|
| 1102 | + { |
|
| 1103 | + $field = $this->describeField($column, $tablename); |
|
| 1104 | + $field['name'] = $newname; |
|
| 1105 | + return "ALTER TABLE $tablename CHANGE COLUMN $column ".$this->oneColumnSQLRep($field); |
|
| 1106 | + } |
|
| 1107 | + |
|
| 1108 | + public function emptyValue($type) |
|
| 1109 | + { |
|
| 1110 | + $ctype = $this->getColumnType($type); |
|
| 1111 | + if($ctype == "datetime") { |
|
| 1112 | + return 'NULL'; |
|
| 1113 | + } |
|
| 1114 | + if($ctype == "date") { |
|
| 1115 | + return 'NULL'; |
|
| 1116 | + } |
|
| 1117 | + if($ctype == "time") { |
|
| 1118 | + return 'NULL'; |
|
| 1119 | + } |
|
| 1120 | + return parent::emptyValue($type); |
|
| 1121 | + } |
|
| 1122 | + |
|
| 1123 | + /** |
|
| 1124 | + * (non-PHPdoc) |
|
| 1125 | + * @see DBManager::lastDbError() |
|
| 1126 | + */ |
|
| 1127 | + public function lastDbError() |
|
| 1128 | + { |
|
| 1129 | + if($this->database) { |
|
| 1130 | + if(mysql_errno($this->database)) { |
|
| 1131 | + return "MySQL error ".mysql_errno($this->database).": ".mysql_error($this->database); |
|
| 1132 | + } |
|
| 1133 | + } else { |
|
| 1134 | + $err = mysql_error(); |
|
| 1135 | + if($err) { |
|
| 1136 | + return $err; |
|
| 1137 | + } |
|
| 1138 | + } |
|
| 1139 | 1139 | return false; |
| 1140 | 1140 | } |
| 1141 | 1141 | |
| 1142 | - /** |
|
| 1143 | - * Quote MySQL search term |
|
| 1144 | - * @param unknown_type $term |
|
| 1145 | - */ |
|
| 1146 | - protected function quoteTerm($term) |
|
| 1147 | - { |
|
| 1148 | - if(strpos($term, ' ') !== false) { |
|
| 1149 | - return '"'.$term.'"'; |
|
| 1150 | - } |
|
| 1151 | - return $term; |
|
| 1152 | - } |
|
| 1153 | - |
|
| 1154 | - /** |
|
| 1155 | - * Generate fulltext query from set of terms |
|
| 1156 | - * @param string $fields Field to search against |
|
| 1157 | - * @param array $terms Search terms that may be or not be in the result |
|
| 1158 | - * @param array $must_terms Search terms that have to be in the result |
|
| 1159 | - * @param array $exclude_terms Search terms that have to be not in the result |
|
| 1160 | - */ |
|
| 1161 | - public function getFulltextQuery($field, $terms, $must_terms = array(), $exclude_terms = array()) |
|
| 1162 | - { |
|
| 1163 | - $condition = array(); |
|
| 1164 | - foreach($terms as $term) { |
|
| 1165 | - $condition[] = $this->quoteTerm($term); |
|
| 1166 | - } |
|
| 1167 | - foreach($must_terms as $term) { |
|
| 1168 | - $condition[] = "+".$this->quoteTerm($term); |
|
| 1169 | - } |
|
| 1170 | - foreach($exclude_terms as $term) { |
|
| 1171 | - $condition[] = "-".$this->quoteTerm($term); |
|
| 1172 | - } |
|
| 1173 | - $condition = $this->quoted(join(" ",$condition)); |
|
| 1174 | - return "MATCH($field) AGAINST($condition IN BOOLEAN MODE)"; |
|
| 1175 | - } |
|
| 1176 | - |
|
| 1177 | - /** |
|
| 1178 | - * Get list of all defined charsets |
|
| 1179 | - * @return array |
|
| 1180 | - */ |
|
| 1181 | - protected function getCharsetInfo() |
|
| 1182 | - { |
|
| 1183 | - $charsets = array(); |
|
| 1184 | - $res = $this->query("show variables like 'character\\_set\\_%'"); |
|
| 1185 | - while($row = $this->fetchByAssoc($res)) { |
|
| 1186 | - $charsets[$row['Variable_name']] = $row['Value']; |
|
| 1187 | - } |
|
| 1188 | - return $charsets; |
|
| 1189 | - } |
|
| 1190 | - |
|
| 1191 | - public function getDbInfo() |
|
| 1192 | - { |
|
| 1193 | - $charsets = $this->getCharsetInfo(); |
|
| 1194 | - $charset_str = array(); |
|
| 1195 | - foreach($charsets as $name => $value) { |
|
| 1196 | - $charset_str[] = "$name = $value"; |
|
| 1197 | - } |
|
| 1198 | - return array( |
|
| 1199 | - "MySQL Version" => @mysql_get_client_info(), |
|
| 1200 | - "MySQL Host Info" => @mysql_get_host_info($this->database), |
|
| 1201 | - "MySQL Server Info" => @mysql_get_server_info($this->database), |
|
| 1202 | - "MySQL Client Encoding" => @mysql_client_encoding($this->database), |
|
| 1203 | - "MySQL Character Set Settings" => join(", ", $charset_str), |
|
| 1204 | - ); |
|
| 1205 | - } |
|
| 1206 | - |
|
| 1207 | - public function validateQuery($query) |
|
| 1208 | - { |
|
| 1209 | - $res = $this->query("EXPLAIN $query"); |
|
| 1210 | - return !empty($res); |
|
| 1211 | - } |
|
| 1212 | - |
|
| 1213 | - protected function makeTempTableCopy($table) |
|
| 1214 | - { |
|
| 1215 | - $this->log->debug("creating temp table for [$table]..."); |
|
| 1216 | - $result = $this->query("SHOW CREATE TABLE {$table}"); |
|
| 1217 | - if(empty($result)) { |
|
| 1218 | - return false; |
|
| 1219 | - } |
|
| 1220 | - $row = $this->fetchByAssoc($result); |
|
| 1221 | - if(empty($row) || empty($row['Create Table'])) { |
|
| 1222 | - return false; |
|
| 1223 | - } |
|
| 1224 | - $create = $row['Create Table']; |
|
| 1225 | - // rewrite DDL with _temp name |
|
| 1226 | - $tempTableQuery = str_replace("CREATE TABLE `{$table}`", "CREATE TABLE `{$table}__uw_temp`", $create); |
|
| 1227 | - $r2 = $this->query($tempTableQuery); |
|
| 1228 | - if(empty($r2)) { |
|
| 1229 | - return false; |
|
| 1230 | - } |
|
| 1231 | - |
|
| 1232 | - // get sample data into the temp table to test for data/constraint conflicts |
|
| 1233 | - $this->log->debug('inserting temp dataset...'); |
|
| 1234 | - $q3 = "INSERT INTO `{$table}__uw_temp` SELECT * FROM `{$table}` LIMIT 10"; |
|
| 1235 | - $this->query($q3, false, "Preflight Failed for: {$q3}"); |
|
| 1236 | - return true; |
|
| 1237 | - } |
|
| 1238 | - |
|
| 1239 | - /** |
|
| 1240 | - * Tests an ALTER TABLE query |
|
| 1241 | - * @param string table The table name to get DDL |
|
| 1242 | - * @param string query The query to test. |
|
| 1243 | - * @return string Non-empty if error found |
|
| 1244 | - */ |
|
| 1245 | - protected function verifyAlterTable($table, $query) |
|
| 1246 | - { |
|
| 1247 | - $this->log->debug("verifying ALTER TABLE"); |
|
| 1248 | - // Skipping ALTER TABLE [table] DROP PRIMARY KEY because primary keys are not being copied |
|
| 1249 | - // over to the temp tables |
|
| 1250 | - if(strpos(strtoupper($query), 'DROP PRIMARY KEY') !== false) { |
|
| 1251 | - $this->log->debug("Skipping DROP PRIMARY KEY"); |
|
| 1252 | - return ''; |
|
| 1253 | - } |
|
| 1254 | - if(!$this->makeTempTableCopy($table)) { |
|
| 1255 | - return 'Could not create temp table copy'; |
|
| 1256 | - } |
|
| 1257 | - |
|
| 1258 | - // test the query on the test table |
|
| 1259 | - $this->log->debug('testing query: ['.$query.']'); |
|
| 1260 | - $tempTableTestQuery = str_replace("ALTER TABLE `{$table}`", "ALTER TABLE `{$table}__uw_temp`", $query); |
|
| 1261 | - if (strpos($tempTableTestQuery, 'idx') === false) { |
|
| 1262 | - if(strpos($tempTableTestQuery, '__uw_temp') === false) { |
|
| 1263 | - return 'Could not use a temp table to test query!'; |
|
| 1264 | - } |
|
| 1265 | - |
|
| 1266 | - $this->log->debug('testing query on temp table: ['.$tempTableTestQuery.']'); |
|
| 1267 | - $this->query($tempTableTestQuery, false, "Preflight Failed for: {$query}"); |
|
| 1268 | - } else { |
|
| 1269 | - // test insertion of an index on a table |
|
| 1270 | - $tempTableTestQuery_idx = str_replace("ADD INDEX `idx_", "ADD INDEX `temp_idx_", $tempTableTestQuery); |
|
| 1271 | - $this->log->debug('testing query on temp table: ['.$tempTableTestQuery_idx.']'); |
|
| 1272 | - $this->query($tempTableTestQuery_idx, false, "Preflight Failed for: {$query}"); |
|
| 1273 | - } |
|
| 1274 | - $mysqlError = $this->getL(); |
|
| 1275 | - if(!empty($mysqlError)) { |
|
| 1276 | - return $mysqlError; |
|
| 1277 | - } |
|
| 1278 | - $this->dropTableName("{$table}__uw_temp"); |
|
| 1279 | - |
|
| 1280 | - return ''; |
|
| 1281 | - } |
|
| 1282 | - |
|
| 1283 | - protected function verifyGenericReplaceQuery($querytype, $table, $query) |
|
| 1284 | - { |
|
| 1285 | - $this->log->debug("verifying $querytype statement"); |
|
| 1286 | - |
|
| 1287 | - if(!$this->makeTempTableCopy($table)) { |
|
| 1288 | - return 'Could not create temp table copy'; |
|
| 1289 | - } |
|
| 1290 | - // test the query on the test table |
|
| 1291 | - $this->log->debug('testing query: ['.$query.']'); |
|
| 1292 | - $tempTableTestQuery = str_replace("$querytype `{$table}`", "$querytype `{$table}__uw_temp`", $query); |
|
| 1293 | - if(strpos($tempTableTestQuery, '__uw_temp') === false) { |
|
| 1294 | - return 'Could not use a temp table to test query!'; |
|
| 1295 | - } |
|
| 1296 | - |
|
| 1297 | - $this->query($tempTableTestQuery, false, "Preflight Failed for: {$query}"); |
|
| 1298 | - $error = $this->lastError(); // empty on no-errors |
|
| 1299 | - $this->dropTableName("{$table}__uw_temp"); // just in case |
|
| 1300 | - return $error; |
|
| 1301 | - } |
|
| 1302 | - |
|
| 1303 | - /** |
|
| 1304 | - * Tests a DROP TABLE query |
|
| 1305 | - * @param string table The table name to get DDL |
|
| 1306 | - * @param string query The query to test. |
|
| 1307 | - * @return string Non-empty if error found |
|
| 1308 | - */ |
|
| 1309 | - public function verifyDropTable($table, $query) |
|
| 1310 | - { |
|
| 1311 | - return $this->verifyGenericReplaceQuery("DROP TABLE", $table, $query); |
|
| 1312 | - } |
|
| 1313 | - |
|
| 1314 | - /** |
|
| 1315 | - * Tests an INSERT INTO query |
|
| 1316 | - * @param string table The table name to get DDL |
|
| 1317 | - * @param string query The query to test. |
|
| 1318 | - * @return string Non-empty if error found |
|
| 1319 | - */ |
|
| 1320 | - public function verifyInsertInto($table, $query) |
|
| 1321 | - { |
|
| 1322 | - return $this->verifyGenericReplaceQuery("INSERT INTO", $table, $query); |
|
| 1323 | - } |
|
| 1324 | - |
|
| 1325 | - /** |
|
| 1326 | - * Tests an UPDATE query |
|
| 1327 | - * @param string table The table name to get DDL |
|
| 1328 | - * @param string query The query to test. |
|
| 1329 | - * @return string Non-empty if error found |
|
| 1330 | - */ |
|
| 1331 | - public function verifyUpdate($table, $query) |
|
| 1332 | - { |
|
| 1333 | - return $this->verifyGenericReplaceQuery("UPDATE", $table, $query); |
|
| 1334 | - } |
|
| 1335 | - |
|
| 1336 | - /** |
|
| 1337 | - * Tests an DELETE FROM query |
|
| 1338 | - * @param string table The table name to get DDL |
|
| 1339 | - * @param string query The query to test. |
|
| 1340 | - * @return string Non-empty if error found |
|
| 1341 | - */ |
|
| 1342 | - public function verifyDeleteFrom($table, $query) |
|
| 1343 | - { |
|
| 1344 | - return $this->verifyGenericReplaceQuery("DELETE FROM", $table, $query); |
|
| 1345 | - } |
|
| 1346 | - |
|
| 1347 | - /** |
|
| 1348 | - * Check if certain database exists |
|
| 1349 | - * @param string $dbname |
|
| 1350 | - */ |
|
| 1351 | - public function dbExists($dbname) |
|
| 1352 | - { |
|
| 1353 | - $db = $this->getOne("SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = ".$this->quoted($dbname)); |
|
| 1354 | - return !empty($db); |
|
| 1355 | - } |
|
| 1356 | - |
|
| 1357 | - /** |
|
| 1358 | - * Select database |
|
| 1359 | - * @param string $dbname |
|
| 1360 | - */ |
|
| 1361 | - protected function selectDb($dbname) |
|
| 1362 | - { |
|
| 1363 | - return mysql_select_db($dbname); |
|
| 1364 | - } |
|
| 1365 | - |
|
| 1366 | - /** |
|
| 1367 | - * Check if certain DB user exists |
|
| 1368 | - * @param string $username |
|
| 1369 | - */ |
|
| 1370 | - public function userExists($username) |
|
| 1371 | - { |
|
| 1372 | - $db = $this->getOne("SELECT DATABASE()"); |
|
| 1373 | - if(!$this->selectDb("mysql")) { |
|
| 1374 | - return false; |
|
| 1375 | - } |
|
| 1376 | - $user = $this->getOne("select count(*) from user where user = ".$this->quoted($username)); |
|
| 1377 | - if(!$this->selectDb($db)) { |
|
| 1378 | - $this->checkError("Cannot select database $db", true); |
|
| 1379 | - } |
|
| 1380 | - return !empty($user); |
|
| 1381 | - } |
|
| 1382 | - |
|
| 1383 | - /** |
|
| 1384 | - * Create DB user |
|
| 1385 | - * @param string $database_name |
|
| 1386 | - * @param string $host_name |
|
| 1387 | - * @param string $user |
|
| 1388 | - * @param string $password |
|
| 1389 | - */ |
|
| 1390 | - public function createDbUser($database_name, $host_name, $user, $password) |
|
| 1391 | - { |
|
| 1392 | - $qpassword = $this->quote($password); |
|
| 1393 | - $this->query("GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, DROP, INDEX |
|
| 1142 | + /** |
|
| 1143 | + * Quote MySQL search term |
|
| 1144 | + * @param unknown_type $term |
|
| 1145 | + */ |
|
| 1146 | + protected function quoteTerm($term) |
|
| 1147 | + { |
|
| 1148 | + if(strpos($term, ' ') !== false) { |
|
| 1149 | + return '"'.$term.'"'; |
|
| 1150 | + } |
|
| 1151 | + return $term; |
|
| 1152 | + } |
|
| 1153 | + |
|
| 1154 | + /** |
|
| 1155 | + * Generate fulltext query from set of terms |
|
| 1156 | + * @param string $fields Field to search against |
|
| 1157 | + * @param array $terms Search terms that may be or not be in the result |
|
| 1158 | + * @param array $must_terms Search terms that have to be in the result |
|
| 1159 | + * @param array $exclude_terms Search terms that have to be not in the result |
|
| 1160 | + */ |
|
| 1161 | + public function getFulltextQuery($field, $terms, $must_terms = array(), $exclude_terms = array()) |
|
| 1162 | + { |
|
| 1163 | + $condition = array(); |
|
| 1164 | + foreach($terms as $term) { |
|
| 1165 | + $condition[] = $this->quoteTerm($term); |
|
| 1166 | + } |
|
| 1167 | + foreach($must_terms as $term) { |
|
| 1168 | + $condition[] = "+".$this->quoteTerm($term); |
|
| 1169 | + } |
|
| 1170 | + foreach($exclude_terms as $term) { |
|
| 1171 | + $condition[] = "-".$this->quoteTerm($term); |
|
| 1172 | + } |
|
| 1173 | + $condition = $this->quoted(join(" ",$condition)); |
|
| 1174 | + return "MATCH($field) AGAINST($condition IN BOOLEAN MODE)"; |
|
| 1175 | + } |
|
| 1176 | + |
|
| 1177 | + /** |
|
| 1178 | + * Get list of all defined charsets |
|
| 1179 | + * @return array |
|
| 1180 | + */ |
|
| 1181 | + protected function getCharsetInfo() |
|
| 1182 | + { |
|
| 1183 | + $charsets = array(); |
|
| 1184 | + $res = $this->query("show variables like 'character\\_set\\_%'"); |
|
| 1185 | + while($row = $this->fetchByAssoc($res)) { |
|
| 1186 | + $charsets[$row['Variable_name']] = $row['Value']; |
|
| 1187 | + } |
|
| 1188 | + return $charsets; |
|
| 1189 | + } |
|
| 1190 | + |
|
| 1191 | + public function getDbInfo() |
|
| 1192 | + { |
|
| 1193 | + $charsets = $this->getCharsetInfo(); |
|
| 1194 | + $charset_str = array(); |
|
| 1195 | + foreach($charsets as $name => $value) { |
|
| 1196 | + $charset_str[] = "$name = $value"; |
|
| 1197 | + } |
|
| 1198 | + return array( |
|
| 1199 | + "MySQL Version" => @mysql_get_client_info(), |
|
| 1200 | + "MySQL Host Info" => @mysql_get_host_info($this->database), |
|
| 1201 | + "MySQL Server Info" => @mysql_get_server_info($this->database), |
|
| 1202 | + "MySQL Client Encoding" => @mysql_client_encoding($this->database), |
|
| 1203 | + "MySQL Character Set Settings" => join(", ", $charset_str), |
|
| 1204 | + ); |
|
| 1205 | + } |
|
| 1206 | + |
|
| 1207 | + public function validateQuery($query) |
|
| 1208 | + { |
|
| 1209 | + $res = $this->query("EXPLAIN $query"); |
|
| 1210 | + return !empty($res); |
|
| 1211 | + } |
|
| 1212 | + |
|
| 1213 | + protected function makeTempTableCopy($table) |
|
| 1214 | + { |
|
| 1215 | + $this->log->debug("creating temp table for [$table]..."); |
|
| 1216 | + $result = $this->query("SHOW CREATE TABLE {$table}"); |
|
| 1217 | + if(empty($result)) { |
|
| 1218 | + return false; |
|
| 1219 | + } |
|
| 1220 | + $row = $this->fetchByAssoc($result); |
|
| 1221 | + if(empty($row) || empty($row['Create Table'])) { |
|
| 1222 | + return false; |
|
| 1223 | + } |
|
| 1224 | + $create = $row['Create Table']; |
|
| 1225 | + // rewrite DDL with _temp name |
|
| 1226 | + $tempTableQuery = str_replace("CREATE TABLE `{$table}`", "CREATE TABLE `{$table}__uw_temp`", $create); |
|
| 1227 | + $r2 = $this->query($tempTableQuery); |
|
| 1228 | + if(empty($r2)) { |
|
| 1229 | + return false; |
|
| 1230 | + } |
|
| 1231 | + |
|
| 1232 | + // get sample data into the temp table to test for data/constraint conflicts |
|
| 1233 | + $this->log->debug('inserting temp dataset...'); |
|
| 1234 | + $q3 = "INSERT INTO `{$table}__uw_temp` SELECT * FROM `{$table}` LIMIT 10"; |
|
| 1235 | + $this->query($q3, false, "Preflight Failed for: {$q3}"); |
|
| 1236 | + return true; |
|
| 1237 | + } |
|
| 1238 | + |
|
| 1239 | + /** |
|
| 1240 | + * Tests an ALTER TABLE query |
|
| 1241 | + * @param string table The table name to get DDL |
|
| 1242 | + * @param string query The query to test. |
|
| 1243 | + * @return string Non-empty if error found |
|
| 1244 | + */ |
|
| 1245 | + protected function verifyAlterTable($table, $query) |
|
| 1246 | + { |
|
| 1247 | + $this->log->debug("verifying ALTER TABLE"); |
|
| 1248 | + // Skipping ALTER TABLE [table] DROP PRIMARY KEY because primary keys are not being copied |
|
| 1249 | + // over to the temp tables |
|
| 1250 | + if(strpos(strtoupper($query), 'DROP PRIMARY KEY') !== false) { |
|
| 1251 | + $this->log->debug("Skipping DROP PRIMARY KEY"); |
|
| 1252 | + return ''; |
|
| 1253 | + } |
|
| 1254 | + if(!$this->makeTempTableCopy($table)) { |
|
| 1255 | + return 'Could not create temp table copy'; |
|
| 1256 | + } |
|
| 1257 | + |
|
| 1258 | + // test the query on the test table |
|
| 1259 | + $this->log->debug('testing query: ['.$query.']'); |
|
| 1260 | + $tempTableTestQuery = str_replace("ALTER TABLE `{$table}`", "ALTER TABLE `{$table}__uw_temp`", $query); |
|
| 1261 | + if (strpos($tempTableTestQuery, 'idx') === false) { |
|
| 1262 | + if(strpos($tempTableTestQuery, '__uw_temp') === false) { |
|
| 1263 | + return 'Could not use a temp table to test query!'; |
|
| 1264 | + } |
|
| 1265 | + |
|
| 1266 | + $this->log->debug('testing query on temp table: ['.$tempTableTestQuery.']'); |
|
| 1267 | + $this->query($tempTableTestQuery, false, "Preflight Failed for: {$query}"); |
|
| 1268 | + } else { |
|
| 1269 | + // test insertion of an index on a table |
|
| 1270 | + $tempTableTestQuery_idx = str_replace("ADD INDEX `idx_", "ADD INDEX `temp_idx_", $tempTableTestQuery); |
|
| 1271 | + $this->log->debug('testing query on temp table: ['.$tempTableTestQuery_idx.']'); |
|
| 1272 | + $this->query($tempTableTestQuery_idx, false, "Preflight Failed for: {$query}"); |
|
| 1273 | + } |
|
| 1274 | + $mysqlError = $this->getL(); |
|
| 1275 | + if(!empty($mysqlError)) { |
|
| 1276 | + return $mysqlError; |
|
| 1277 | + } |
|
| 1278 | + $this->dropTableName("{$table}__uw_temp"); |
|
| 1279 | + |
|
| 1280 | + return ''; |
|
| 1281 | + } |
|
| 1282 | + |
|
| 1283 | + protected function verifyGenericReplaceQuery($querytype, $table, $query) |
|
| 1284 | + { |
|
| 1285 | + $this->log->debug("verifying $querytype statement"); |
|
| 1286 | + |
|
| 1287 | + if(!$this->makeTempTableCopy($table)) { |
|
| 1288 | + return 'Could not create temp table copy'; |
|
| 1289 | + } |
|
| 1290 | + // test the query on the test table |
|
| 1291 | + $this->log->debug('testing query: ['.$query.']'); |
|
| 1292 | + $tempTableTestQuery = str_replace("$querytype `{$table}`", "$querytype `{$table}__uw_temp`", $query); |
|
| 1293 | + if(strpos($tempTableTestQuery, '__uw_temp') === false) { |
|
| 1294 | + return 'Could not use a temp table to test query!'; |
|
| 1295 | + } |
|
| 1296 | + |
|
| 1297 | + $this->query($tempTableTestQuery, false, "Preflight Failed for: {$query}"); |
|
| 1298 | + $error = $this->lastError(); // empty on no-errors |
|
| 1299 | + $this->dropTableName("{$table}__uw_temp"); // just in case |
|
| 1300 | + return $error; |
|
| 1301 | + } |
|
| 1302 | + |
|
| 1303 | + /** |
|
| 1304 | + * Tests a DROP TABLE query |
|
| 1305 | + * @param string table The table name to get DDL |
|
| 1306 | + * @param string query The query to test. |
|
| 1307 | + * @return string Non-empty if error found |
|
| 1308 | + */ |
|
| 1309 | + public function verifyDropTable($table, $query) |
|
| 1310 | + { |
|
| 1311 | + return $this->verifyGenericReplaceQuery("DROP TABLE", $table, $query); |
|
| 1312 | + } |
|
| 1313 | + |
|
| 1314 | + /** |
|
| 1315 | + * Tests an INSERT INTO query |
|
| 1316 | + * @param string table The table name to get DDL |
|
| 1317 | + * @param string query The query to test. |
|
| 1318 | + * @return string Non-empty if error found |
|
| 1319 | + */ |
|
| 1320 | + public function verifyInsertInto($table, $query) |
|
| 1321 | + { |
|
| 1322 | + return $this->verifyGenericReplaceQuery("INSERT INTO", $table, $query); |
|
| 1323 | + } |
|
| 1324 | + |
|
| 1325 | + /** |
|
| 1326 | + * Tests an UPDATE query |
|
| 1327 | + * @param string table The table name to get DDL |
|
| 1328 | + * @param string query The query to test. |
|
| 1329 | + * @return string Non-empty if error found |
|
| 1330 | + */ |
|
| 1331 | + public function verifyUpdate($table, $query) |
|
| 1332 | + { |
|
| 1333 | + return $this->verifyGenericReplaceQuery("UPDATE", $table, $query); |
|
| 1334 | + } |
|
| 1335 | + |
|
| 1336 | + /** |
|
| 1337 | + * Tests an DELETE FROM query |
|
| 1338 | + * @param string table The table name to get DDL |
|
| 1339 | + * @param string query The query to test. |
|
| 1340 | + * @return string Non-empty if error found |
|
| 1341 | + */ |
|
| 1342 | + public function verifyDeleteFrom($table, $query) |
|
| 1343 | + { |
|
| 1344 | + return $this->verifyGenericReplaceQuery("DELETE FROM", $table, $query); |
|
| 1345 | + } |
|
| 1346 | + |
|
| 1347 | + /** |
|
| 1348 | + * Check if certain database exists |
|
| 1349 | + * @param string $dbname |
|
| 1350 | + */ |
|
| 1351 | + public function dbExists($dbname) |
|
| 1352 | + { |
|
| 1353 | + $db = $this->getOne("SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = ".$this->quoted($dbname)); |
|
| 1354 | + return !empty($db); |
|
| 1355 | + } |
|
| 1356 | + |
|
| 1357 | + /** |
|
| 1358 | + * Select database |
|
| 1359 | + * @param string $dbname |
|
| 1360 | + */ |
|
| 1361 | + protected function selectDb($dbname) |
|
| 1362 | + { |
|
| 1363 | + return mysql_select_db($dbname); |
|
| 1364 | + } |
|
| 1365 | + |
|
| 1366 | + /** |
|
| 1367 | + * Check if certain DB user exists |
|
| 1368 | + * @param string $username |
|
| 1369 | + */ |
|
| 1370 | + public function userExists($username) |
|
| 1371 | + { |
|
| 1372 | + $db = $this->getOne("SELECT DATABASE()"); |
|
| 1373 | + if(!$this->selectDb("mysql")) { |
|
| 1374 | + return false; |
|
| 1375 | + } |
|
| 1376 | + $user = $this->getOne("select count(*) from user where user = ".$this->quoted($username)); |
|
| 1377 | + if(!$this->selectDb($db)) { |
|
| 1378 | + $this->checkError("Cannot select database $db", true); |
|
| 1379 | + } |
|
| 1380 | + return !empty($user); |
|
| 1381 | + } |
|
| 1382 | + |
|
| 1383 | + /** |
|
| 1384 | + * Create DB user |
|
| 1385 | + * @param string $database_name |
|
| 1386 | + * @param string $host_name |
|
| 1387 | + * @param string $user |
|
| 1388 | + * @param string $password |
|
| 1389 | + */ |
|
| 1390 | + public function createDbUser($database_name, $host_name, $user, $password) |
|
| 1391 | + { |
|
| 1392 | + $qpassword = $this->quote($password); |
|
| 1393 | + $this->query("GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, DROP, INDEX |
|
| 1394 | 1394 | ON `$database_name`.* |
| 1395 | 1395 | TO \"$user\"@\"$host_name\" |
| 1396 | 1396 | IDENTIFIED BY '{$qpassword}';", true); |
| 1397 | 1397 | |
| 1398 | - $this->query("SET PASSWORD FOR \"{$user}\"@\"{$host_name}\" = password('{$qpassword}');", true); |
|
| 1399 | - if($host_name != 'localhost') { |
|
| 1400 | - $this->createDbUser($database_name, "localhost", $user, $password); |
|
| 1401 | - } |
|
| 1402 | - } |
|
| 1403 | - |
|
| 1404 | - /** |
|
| 1405 | - * Create a database |
|
| 1406 | - * @param string $dbname |
|
| 1407 | - */ |
|
| 1408 | - public function createDatabase($dbname) |
|
| 1409 | - { |
|
| 1410 | - $this->query("CREATE DATABASE `$dbname` CHARACTER SET utf8 COLLATE utf8_general_ci", true); |
|
| 1411 | - } |
|
| 1412 | - |
|
| 1413 | - public function preInstall() |
|
| 1414 | - { |
|
| 1415 | - $db->query("ALTER DATABASE `{$setup_db_database_name}` DEFAULT CHARACTER SET utf8", true); |
|
| 1416 | - $db->query("ALTER DATABASE `{$setup_db_database_name}` DEFAULT COLLATE utf8_general_ci", true); |
|
| 1417 | - |
|
| 1418 | - } |
|
| 1419 | - |
|
| 1420 | - /** |
|
| 1421 | - * Drop a database |
|
| 1422 | - * @param string $dbname |
|
| 1423 | - */ |
|
| 1424 | - public function dropDatabase($dbname) |
|
| 1425 | - { |
|
| 1426 | - return $this->query("DROP DATABASE IF EXISTS `$dbname`", true); |
|
| 1427 | - } |
|
| 1428 | - |
|
| 1429 | - /** |
|
| 1430 | - * Check if this driver can be used |
|
| 1431 | - * @return bool |
|
| 1432 | - */ |
|
| 1433 | - public function valid() |
|
| 1434 | - { |
|
| 1435 | - return function_exists("mysql_connect"); |
|
| 1436 | - } |
|
| 1437 | - |
|
| 1438 | - /** |
|
| 1439 | - * Check DB version |
|
| 1440 | - * @see DBManager::canInstall() |
|
| 1441 | - */ |
|
| 1442 | - public function canInstall() |
|
| 1443 | - { |
|
| 1444 | - $db_version = $this->version(); |
|
| 1445 | - if(empty($db_version)) { |
|
| 1446 | - return array('ERR_DB_VERSION_FAILURE'); |
|
| 1447 | - } |
|
| 1448 | - if(version_compare($db_version, '4.1.2') < 0) { |
|
| 1449 | - return array('ERR_DB_MYSQL_VERSION', $db_version); |
|
| 1450 | - } |
|
| 1451 | - return true; |
|
| 1452 | - } |
|
| 1453 | - |
|
| 1454 | - public function installConfig() |
|
| 1455 | - { |
|
| 1456 | - return array( |
|
| 1457 | - 'LBL_DBCONFIG_MSG3' => array( |
|
| 1458 | - "setup_db_database_name" => array("label" => 'LBL_DBCONF_DB_NAME', "required" => true), |
|
| 1459 | - ), |
|
| 1460 | - 'LBL_DBCONFIG_MSG2' => array( |
|
| 1461 | - "setup_db_host_name" => array("label" => 'LBL_DBCONF_HOST_NAME', "required" => true), |
|
| 1462 | - ), |
|
| 1463 | - 'LBL_DBCONF_TITLE_USER_INFO' => array(), |
|
| 1464 | - 'LBL_DBCONFIG_B_MSG1' => array( |
|
| 1465 | - "setup_db_admin_user_name" => array("label" => 'LBL_DBCONF_DB_ADMIN_USER', "required" => true), |
|
| 1466 | - "setup_db_admin_password" => array("label" => 'LBL_DBCONF_DB_ADMIN_PASSWORD', "type" => "password"), |
|
| 1467 | - ) |
|
| 1468 | - ); |
|
| 1469 | - } |
|
| 1470 | - |
|
| 1471 | - /** |
|
| 1472 | - * Disable keys on the table |
|
| 1473 | - * @abstract |
|
| 1474 | - * @param string $tableName |
|
| 1475 | - */ |
|
| 1476 | - public function disableKeys($tableName) |
|
| 1477 | - { |
|
| 1478 | - return $this->query('ALTER TABLE '.$tableName.' DISABLE KEYS'); |
|
| 1479 | - } |
|
| 1480 | - |
|
| 1481 | - /** |
|
| 1482 | - * Re-enable keys on the table |
|
| 1483 | - * @abstract |
|
| 1484 | - * @param string $tableName |
|
| 1485 | - */ |
|
| 1486 | - public function enableKeys($tableName) |
|
| 1487 | - { |
|
| 1488 | - return $this->query('ALTER TABLE '.$tableName.' ENABLE KEYS'); |
|
| 1489 | - } |
|
| 1398 | + $this->query("SET PASSWORD FOR \"{$user}\"@\"{$host_name}\" = password('{$qpassword}');", true); |
|
| 1399 | + if($host_name != 'localhost') { |
|
| 1400 | + $this->createDbUser($database_name, "localhost", $user, $password); |
|
| 1401 | + } |
|
| 1402 | + } |
|
| 1403 | + |
|
| 1404 | + /** |
|
| 1405 | + * Create a database |
|
| 1406 | + * @param string $dbname |
|
| 1407 | + */ |
|
| 1408 | + public function createDatabase($dbname) |
|
| 1409 | + { |
|
| 1410 | + $this->query("CREATE DATABASE `$dbname` CHARACTER SET utf8 COLLATE utf8_general_ci", true); |
|
| 1411 | + } |
|
| 1412 | + |
|
| 1413 | + public function preInstall() |
|
| 1414 | + { |
|
| 1415 | + $db->query("ALTER DATABASE `{$setup_db_database_name}` DEFAULT CHARACTER SET utf8", true); |
|
| 1416 | + $db->query("ALTER DATABASE `{$setup_db_database_name}` DEFAULT COLLATE utf8_general_ci", true); |
|
| 1417 | + |
|
| 1418 | + } |
|
| 1419 | + |
|
| 1420 | + /** |
|
| 1421 | + * Drop a database |
|
| 1422 | + * @param string $dbname |
|
| 1423 | + */ |
|
| 1424 | + public function dropDatabase($dbname) |
|
| 1425 | + { |
|
| 1426 | + return $this->query("DROP DATABASE IF EXISTS `$dbname`", true); |
|
| 1427 | + } |
|
| 1428 | + |
|
| 1429 | + /** |
|
| 1430 | + * Check if this driver can be used |
|
| 1431 | + * @return bool |
|
| 1432 | + */ |
|
| 1433 | + public function valid() |
|
| 1434 | + { |
|
| 1435 | + return function_exists("mysql_connect"); |
|
| 1436 | + } |
|
| 1437 | + |
|
| 1438 | + /** |
|
| 1439 | + * Check DB version |
|
| 1440 | + * @see DBManager::canInstall() |
|
| 1441 | + */ |
|
| 1442 | + public function canInstall() |
|
| 1443 | + { |
|
| 1444 | + $db_version = $this->version(); |
|
| 1445 | + if(empty($db_version)) { |
|
| 1446 | + return array('ERR_DB_VERSION_FAILURE'); |
|
| 1447 | + } |
|
| 1448 | + if(version_compare($db_version, '4.1.2') < 0) { |
|
| 1449 | + return array('ERR_DB_MYSQL_VERSION', $db_version); |
|
| 1450 | + } |
|
| 1451 | + return true; |
|
| 1452 | + } |
|
| 1453 | + |
|
| 1454 | + public function installConfig() |
|
| 1455 | + { |
|
| 1456 | + return array( |
|
| 1457 | + 'LBL_DBCONFIG_MSG3' => array( |
|
| 1458 | + "setup_db_database_name" => array("label" => 'LBL_DBCONF_DB_NAME', "required" => true), |
|
| 1459 | + ), |
|
| 1460 | + 'LBL_DBCONFIG_MSG2' => array( |
|
| 1461 | + "setup_db_host_name" => array("label" => 'LBL_DBCONF_HOST_NAME', "required" => true), |
|
| 1462 | + ), |
|
| 1463 | + 'LBL_DBCONF_TITLE_USER_INFO' => array(), |
|
| 1464 | + 'LBL_DBCONFIG_B_MSG1' => array( |
|
| 1465 | + "setup_db_admin_user_name" => array("label" => 'LBL_DBCONF_DB_ADMIN_USER', "required" => true), |
|
| 1466 | + "setup_db_admin_password" => array("label" => 'LBL_DBCONF_DB_ADMIN_PASSWORD', "type" => "password"), |
|
| 1467 | + ) |
|
| 1468 | + ); |
|
| 1469 | + } |
|
| 1470 | + |
|
| 1471 | + /** |
|
| 1472 | + * Disable keys on the table |
|
| 1473 | + * @abstract |
|
| 1474 | + * @param string $tableName |
|
| 1475 | + */ |
|
| 1476 | + public function disableKeys($tableName) |
|
| 1477 | + { |
|
| 1478 | + return $this->query('ALTER TABLE '.$tableName.' DISABLE KEYS'); |
|
| 1479 | + } |
|
| 1480 | + |
|
| 1481 | + /** |
|
| 1482 | + * Re-enable keys on the table |
|
| 1483 | + * @abstract |
|
| 1484 | + * @param string $tableName |
|
| 1485 | + */ |
|
| 1486 | + public function enableKeys($tableName) |
|
| 1487 | + { |
|
| 1488 | + return $this->query('ALTER TABLE '.$tableName.' ENABLE KEYS'); |
|
| 1489 | + } |
|
| 1490 | 1490 | |
| 1491 | 1491 | /** |
| 1492 | 1492 | * Returns a DB specific FROM clause which can be used to select against functions. |
@@ -1505,8 +1505,8 @@ discard block |
||
| 1505 | 1505 | * @return string |
| 1506 | 1506 | */ |
| 1507 | 1507 | |
| 1508 | - public function getGuidSQL() |
|
| 1508 | + public function getGuidSQL() |
|
| 1509 | 1509 | { |
| 1510 | - return 'UUID()'; |
|
| 1510 | + return 'UUID()'; |
|
| 1511 | 1511 | } |
| 1512 | 1512 | } |
@@ -174,25 +174,25 @@ discard block |
||
| 174 | 174 | */ |
| 175 | 175 | public function query($sql, $dieOnError = false, $msg = '', $suppress = false, $keepResult = false) |
| 176 | 176 | { |
| 177 | - if(is_array($sql)) { |
|
| 177 | + if (is_array($sql)) { |
|
| 178 | 178 | return $this->queryArray($sql, $dieOnError, $msg, $suppress); |
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | parent::countQuery($sql); |
| 182 | - $GLOBALS['log']->info('Query:' . $sql); |
|
| 182 | + $GLOBALS['log']->info('Query:'.$sql); |
|
| 183 | 183 | $this->checkConnection(); |
| 184 | 184 | $this->query_time = microtime(true); |
| 185 | 185 | $this->lastsql = $sql; |
| 186 | - $result = $suppress?@mysql_query($sql, $this->database):mysql_query($sql, $this->database); |
|
| 186 | + $result = $suppress ? @mysql_query($sql, $this->database) : mysql_query($sql, $this->database); |
|
| 187 | 187 | |
| 188 | 188 | $this->query_time = microtime(true) - $this->query_time; |
| 189 | 189 | $GLOBALS['log']->info('Query Execution Time:'.$this->query_time); |
| 190 | 190 | |
| 191 | 191 | |
| 192 | - if($keepResult) |
|
| 192 | + if ($keepResult) |
|
| 193 | 193 | $this->lastResult = $result; |
| 194 | 194 | |
| 195 | - $this->checkError($msg.' Query Failed:' . $sql . '::', $dieOnError); |
|
| 195 | + $this->checkError($msg.' Query Failed:'.$sql.'::', $dieOnError); |
|
| 196 | 196 | return $result; |
| 197 | 197 | } |
| 198 | 198 | |
@@ -228,7 +228,7 @@ discard block |
||
| 228 | 228 | public function disconnect() |
| 229 | 229 | { |
| 230 | 230 | $GLOBALS['log']->debug('Calling MySQL::disconnect()'); |
| 231 | - if(!empty($this->database)){ |
|
| 231 | + if (!empty($this->database)) { |
|
| 232 | 232 | $this->freeResult(); |
| 233 | 233 | mysql_close($this->database); |
| 234 | 234 | $this->database = null; |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | */ |
| 241 | 241 | protected function freeDbResult($dbResult) |
| 242 | 242 | { |
| 243 | - if(!empty($dbResult)) |
|
| 243 | + if (!empty($dbResult)) |
|
| 244 | 244 | mysql_free_result($dbResult); |
| 245 | 245 | } |
| 246 | 246 | |
@@ -266,15 +266,15 @@ discard block |
||
| 266 | 266 | $count = (int)$count; |
| 267 | 267 | if ($start < 0) |
| 268 | 268 | $start = 0; |
| 269 | - $GLOBALS['log']->debug('Limit Query:' . $sql. ' Start: ' .$start . ' count: ' . $count); |
|
| 269 | + $GLOBALS['log']->debug('Limit Query:'.$sql.' Start: '.$start.' count: '.$count); |
|
| 270 | 270 | |
| 271 | 271 | $sql = "$sql LIMIT $start,$count"; |
| 272 | 272 | $this->lastsql = $sql; |
| 273 | 273 | |
| 274 | - if(!empty($GLOBALS['sugar_config']['check_query'])){ |
|
| 274 | + if (!empty($GLOBALS['sugar_config']['check_query'])) { |
|
| 275 | 275 | $this->checkQuery($sql); |
| 276 | 276 | } |
| 277 | - if(!$execute) { |
|
| 277 | + if (!$execute) { |
|
| 278 | 278 | return $sql; |
| 279 | 279 | } |
| 280 | 280 | |
@@ -287,14 +287,14 @@ discard block |
||
| 287 | 287 | */ |
| 288 | 288 | protected function checkQuery($sql, $object_name = false) |
| 289 | 289 | { |
| 290 | - $result = $this->query('EXPLAIN ' . $sql); |
|
| 290 | + $result = $this->query('EXPLAIN '.$sql); |
|
| 291 | 291 | $badQuery = array(); |
| 292 | 292 | while ($row = $this->fetchByAssoc($result)) { |
| 293 | 293 | if (empty($row['table'])) |
| 294 | 294 | continue; |
| 295 | 295 | $badQuery[$row['table']] = ''; |
| 296 | 296 | if (strtoupper($row['type']) == 'ALL') |
| 297 | - $badQuery[$row['table']] .= ' Full Table Scan;'; |
|
| 297 | + $badQuery[$row['table']] .= ' Full Table Scan;'; |
|
| 298 | 298 | if (empty($row['key'])) |
| 299 | 299 | $badQuery[$row['table']] .= ' No Index Key Used;'; |
| 300 | 300 | if (!empty($row['Extra']) && substr_count($row['Extra'], 'Using filesort') > 0) |
@@ -303,18 +303,18 @@ discard block |
||
| 303 | 303 | $badQuery[$row['table']] .= ' Using Temporary Table;'; |
| 304 | 304 | } |
| 305 | 305 | |
| 306 | - if ( empty($badQuery) ) |
|
| 306 | + if (empty($badQuery)) |
|
| 307 | 307 | return true; |
| 308 | 308 | |
| 309 | - foreach($badQuery as $table=>$data ){ |
|
| 310 | - if(!empty($data)){ |
|
| 311 | - $warning = ' Table:' . $table . ' Data:' . $data; |
|
| 312 | - if(!empty($GLOBALS['sugar_config']['check_query_log'])){ |
|
| 309 | + foreach ($badQuery as $table=>$data) { |
|
| 310 | + if (!empty($data)) { |
|
| 311 | + $warning = ' Table:'.$table.' Data:'.$data; |
|
| 312 | + if (!empty($GLOBALS['sugar_config']['check_query_log'])) { |
|
| 313 | 313 | $GLOBALS['log']->fatal($sql); |
| 314 | - $GLOBALS['log']->fatal('CHECK QUERY:' .$warning); |
|
| 314 | + $GLOBALS['log']->fatal('CHECK QUERY:'.$warning); |
|
| 315 | 315 | } |
| 316 | - else{ |
|
| 317 | - $GLOBALS['log']->warn('CHECK QUERY:' .$warning); |
|
| 316 | + else { |
|
| 317 | + $GLOBALS['log']->warn('CHECK QUERY:'.$warning); |
|
| 318 | 318 | } |
| 319 | 319 | } |
| 320 | 320 | } |
@@ -331,19 +331,19 @@ discard block |
||
| 331 | 331 | $result = $this->query("DESCRIBE $tablename"); |
| 332 | 332 | |
| 333 | 333 | $columns = array(); |
| 334 | - while (($row=$this->fetchByAssoc($result)) !=null) { |
|
| 334 | + while (($row = $this->fetchByAssoc($result)) != null) { |
|
| 335 | 335 | $name = strtolower($row['Field']); |
| 336 | - $columns[$name]['name']=$name; |
|
| 336 | + $columns[$name]['name'] = $name; |
|
| 337 | 337 | $matches = array(); |
| 338 | 338 | preg_match_all('/(\w+)(?:\(([0-9]+,?[0-9]*)\)|)( unsigned)?/i', $row['Type'], $matches); |
| 339 | - $columns[$name]['type']=strtolower($matches[1][0]); |
|
| 340 | - if ( isset($matches[2][0]) && in_array(strtolower($matches[1][0]),array('varchar','char','varchar2','int','decimal','float')) ) |
|
| 341 | - $columns[$name]['len']=strtolower($matches[2][0]); |
|
| 342 | - if ( stristr($row['Extra'],'auto_increment') ) |
|
| 339 | + $columns[$name]['type'] = strtolower($matches[1][0]); |
|
| 340 | + if (isset($matches[2][0]) && in_array(strtolower($matches[1][0]), array('varchar', 'char', 'varchar2', 'int', 'decimal', 'float'))) |
|
| 341 | + $columns[$name]['len'] = strtolower($matches[2][0]); |
|
| 342 | + if (stristr($row['Extra'], 'auto_increment')) |
|
| 343 | 343 | $columns[$name]['auto_increment'] = '1'; |
| 344 | - if ($row['Null'] == 'NO' && !stristr($row['Key'],'PRI')) |
|
| 344 | + if ($row['Null'] == 'NO' && !stristr($row['Key'], 'PRI')) |
|
| 345 | 345 | $columns[$name]['required'] = 'true'; |
| 346 | - if (!empty($row['Default']) ) |
|
| 346 | + if (!empty($row['Default'])) |
|
| 347 | 347 | $columns[$name]['default'] = $row['Default']; |
| 348 | 348 | } |
| 349 | 349 | return $columns; |
@@ -352,20 +352,20 @@ discard block |
||
| 352 | 352 | /** |
| 353 | 353 | * @see DBManager::getFieldsArray() |
| 354 | 354 | */ |
| 355 | - public function getFieldsArray($result, $make_lower_case=false) |
|
| 355 | + public function getFieldsArray($result, $make_lower_case = false) |
|
| 356 | 356 | { |
| 357 | 357 | $field_array = array(); |
| 358 | 358 | |
| 359 | - if(empty($result)) |
|
| 359 | + if (empty($result)) |
|
| 360 | 360 | return 0; |
| 361 | 361 | |
| 362 | 362 | $fields = mysql_num_fields($result); |
| 363 | - for ($i=0; $i < $fields; $i++) { |
|
| 363 | + for ($i = 0; $i < $fields; $i++) { |
|
| 364 | 364 | $meta = mysql_fetch_field($result, $i); |
| 365 | 365 | if (!$meta) |
| 366 | 366 | return array(); |
| 367 | 367 | |
| 368 | - if($make_lower_case == true) |
|
| 368 | + if ($make_lower_case == true) |
|
| 369 | 369 | $meta->name = strtolower($meta->name); |
| 370 | 370 | |
| 371 | 371 | $field_array[] = $meta->name; |
@@ -397,7 +397,7 @@ discard block |
||
| 397 | 397 | if (!empty($r)) { |
| 398 | 398 | while ($a = $this->fetchByAssoc($r)) { |
| 399 | 399 | $row = array_values($a); |
| 400 | - $tables[]=$row[0]; |
|
| 400 | + $tables[] = $row[0]; |
|
| 401 | 401 | } |
| 402 | 402 | return $tables; |
| 403 | 403 | } |
@@ -423,7 +423,7 @@ discard block |
||
| 423 | 423 | |
| 424 | 424 | if ($this->getDatabase()) { |
| 425 | 425 | $result = $this->query("SHOW TABLES LIKE ".$this->quoted($tableName)); |
| 426 | - if(empty($result)) return false; |
|
| 426 | + if (empty($result)) return false; |
|
| 427 | 427 | $row = $this->fetchByAssoc($result); |
| 428 | 428 | return !empty($row); |
| 429 | 429 | } |
@@ -444,7 +444,7 @@ discard block |
||
| 444 | 444 | if (!empty($r)) { |
| 445 | 445 | while ($a = $this->fetchByAssoc($r)) { |
| 446 | 446 | $row = array_values($a); |
| 447 | - $tables[]=$row[0]; |
|
| 447 | + $tables[] = $row[0]; |
|
| 448 | 448 | } |
| 449 | 449 | return $tables; |
| 450 | 450 | } |
@@ -457,7 +457,7 @@ discard block |
||
| 457 | 457 | */ |
| 458 | 458 | public function quote($string) |
| 459 | 459 | { |
| 460 | - if(is_array($string)) { |
|
| 460 | + if (is_array($string)) { |
|
| 461 | 461 | return $this->arrayQuote($string); |
| 462 | 462 | } |
| 463 | 463 | return mysqli_real_escape_string($this->quoteInternal($string), $this->getDatabase()); |
@@ -478,7 +478,7 @@ discard block |
||
| 478 | 478 | { |
| 479 | 479 | global $sugar_config; |
| 480 | 480 | |
| 481 | - if(is_null($configOptions)) |
|
| 481 | + if (is_null($configOptions)) |
|
| 482 | 482 | $configOptions = $sugar_config['dbconfig']; |
| 483 | 483 | |
| 484 | 484 | if ($this->getOption('persistent')) { |
@@ -495,10 +495,10 @@ discard block |
||
| 495 | 495 | $configOptions['db_user_name'], |
| 496 | 496 | $configOptions['db_password'] |
| 497 | 497 | ); |
| 498 | - if(empty($this->database)) { |
|
| 498 | + if (empty($this->database)) { |
|
| 499 | 499 | $GLOBALS['log']->fatal("Could not connect to server ".$configOptions['db_host_name']." as ".$configOptions['db_user_name'].":".mysql_error()); |
| 500 | - if($dieOnError) { |
|
| 501 | - if(isset($GLOBALS['app_strings']['ERR_NO_DB'])) { |
|
| 500 | + if ($dieOnError) { |
|
| 501 | + if (isset($GLOBALS['app_strings']['ERR_NO_DB'])) { |
|
| 502 | 502 | sugar_die($GLOBALS['app_strings']['ERR_NO_DB']); |
| 503 | 503 | } else { |
| 504 | 504 | sugar_die("Could not connect to the database. Please refer to suitecrm.log for details."); |
@@ -508,15 +508,15 @@ discard block |
||
| 508 | 508 | } |
| 509 | 509 | } |
| 510 | 510 | // Do not pass connection information because we have not connected yet |
| 511 | - if($this->database && $this->getOption('persistent')){ |
|
| 511 | + if ($this->database && $this->getOption('persistent')) { |
|
| 512 | 512 | $_SESSION['administrator_error'] = "<b>Severe Performance Degradation: Persistent Database Connections " |
| 513 | 513 | . "not working. Please set \$sugar_config['dbconfigoption']['persistent'] to false " |
| 514 | 514 | . "in your config.php file</b>"; |
| 515 | 515 | } |
| 516 | 516 | } |
| 517 | - if(!empty($configOptions['db_name']) && !@mysql_select_db($configOptions['db_name'])) { |
|
| 518 | - $GLOBALS['log']->fatal( "Unable to select database {$configOptions['db_name']}: " . mysql_error($this->database)); |
|
| 519 | - if($dieOnError) { |
|
| 517 | + if (!empty($configOptions['db_name']) && !@mysql_select_db($configOptions['db_name'])) { |
|
| 518 | + $GLOBALS['log']->fatal("Unable to select database {$configOptions['db_name']}: ".mysql_error($this->database)); |
|
| 519 | + if ($dieOnError) { |
|
| 520 | 520 | sugar_die($GLOBALS['app_strings']['ERR_NO_DB']); |
| 521 | 521 | } else { |
| 522 | 522 | return false; |
@@ -527,12 +527,12 @@ discard block |
||
| 527 | 527 | mysql_query("SET CHARACTER SET utf8", $this->database); |
| 528 | 528 | $names = "SET NAMES 'utf8'"; |
| 529 | 529 | $collation = $this->getOption('collation'); |
| 530 | - if(!empty($collation)) { |
|
| 530 | + if (!empty($collation)) { |
|
| 531 | 531 | $names .= " COLLATE '$collation'"; |
| 532 | 532 | } |
| 533 | 533 | mysql_query($names, $this->database); |
| 534 | 534 | |
| 535 | - if(!$this->checkError('Could Not Connect:', $dieOnError)) |
|
| 535 | + if (!$this->checkError('Could Not Connect:', $dieOnError)) |
|
| 536 | 536 | $GLOBALS['log']->info("connected to db"); |
| 537 | 537 | $this->connectOptions = $configOptions; |
| 538 | 538 | |
@@ -548,16 +548,16 @@ discard block |
||
| 548 | 548 | */ |
| 549 | 549 | public function repairTableParams($tablename, $fielddefs, $indices, $execute = true, $engine = null) |
| 550 | 550 | { |
| 551 | - $sql = parent::repairTableParams($tablename,$fielddefs,$indices,false,$engine); |
|
| 551 | + $sql = parent::repairTableParams($tablename, $fielddefs, $indices, false, $engine); |
|
| 552 | 552 | |
| 553 | - if ( $sql == '' ) |
|
| 553 | + if ($sql == '') |
|
| 554 | 554 | return ''; |
| 555 | 555 | |
| 556 | - if ( stristr($sql,'create table') ) |
|
| 556 | + if (stristr($sql, 'create table')) |
|
| 557 | 557 | { |
| 558 | 558 | if ($execute) { |
| 559 | - $msg = "Error creating table: ".$tablename. ":"; |
|
| 560 | - $this->query($sql,true,$msg); |
|
| 559 | + $msg = "Error creating table: ".$tablename.":"; |
|
| 560 | + $this->query($sql, true, $msg); |
|
| 561 | 561 | } |
| 562 | 562 | return $sql; |
| 563 | 563 | } |
@@ -566,23 +566,23 @@ discard block |
||
| 566 | 566 | $match = array(); |
| 567 | 567 | preg_match_all('!/\*.*?\*/!is', $sql, $match); |
| 568 | 568 | $commentBlocks = $match[0]; |
| 569 | - $sql = preg_replace('!/\*.*?\*/!is','', $sql); |
|
| 569 | + $sql = preg_replace('!/\*.*?\*/!is', '', $sql); |
|
| 570 | 570 | |
| 571 | 571 | // now, we should only have alter table statements |
| 572 | 572 | // let's replace the 'alter table name' part with a comma |
| 573 | - $sql = preg_replace("!alter table $tablename!is",', ', $sql); |
|
| 573 | + $sql = preg_replace("!alter table $tablename!is", ', ', $sql); |
|
| 574 | 574 | |
| 575 | 575 | // re-add it at the beginning |
| 576 | - $sql = substr_replace($sql,'',strpos($sql,','),1); |
|
| 577 | - $sql = str_replace(";","",$sql); |
|
| 578 | - $sql = str_replace("\n","",$sql); |
|
| 576 | + $sql = substr_replace($sql, '', strpos($sql, ','), 1); |
|
| 577 | + $sql = str_replace(";", "", $sql); |
|
| 578 | + $sql = str_replace("\n", "", $sql); |
|
| 579 | 579 | $sql = "ALTER TABLE $tablename $sql"; |
| 580 | 580 | |
| 581 | - if ( $execute ) |
|
| 582 | - $this->query($sql,'Error with MySQL repair table'); |
|
| 581 | + if ($execute) |
|
| 582 | + $this->query($sql, 'Error with MySQL repair table'); |
|
| 583 | 583 | |
| 584 | 584 | // and re-add the comments at the beginning |
| 585 | - $sql = implode("\n",$commentBlocks) . "\n". $sql . "\n"; |
|
| 585 | + $sql = implode("\n", $commentBlocks)."\n".$sql."\n"; |
|
| 586 | 586 | |
| 587 | 587 | return $sql; |
| 588 | 588 | } |
@@ -593,7 +593,7 @@ discard block |
||
| 593 | 593 | public function convert($string, $type, array $additional_parameters = array()) |
| 594 | 594 | { |
| 595 | 595 | $all_parameters = $additional_parameters; |
| 596 | - if(is_array($string)) { |
|
| 596 | + if (is_array($string)) { |
|
| 597 | 597 | $all_parameters = array_merge($string, $all_parameters); |
| 598 | 598 | } elseif (!is_null($string)) { |
| 599 | 599 | array_unshift($all_parameters, $string); |
@@ -606,17 +606,17 @@ discard block |
||
| 606 | 606 | case 'left': |
| 607 | 607 | return "LEFT($all_strings)"; |
| 608 | 608 | case 'date_format': |
| 609 | - if(empty($additional_parameters)) { |
|
| 609 | + if (empty($additional_parameters)) { |
|
| 610 | 610 | return "DATE_FORMAT($string,'%Y-%m-%d')"; |
| 611 | 611 | } else { |
| 612 | 612 | $format = $additional_parameters[0]; |
| 613 | - if($format[0] != "'") { |
|
| 613 | + if ($format[0] != "'") { |
|
| 614 | 614 | $format = $this->quoted($format); |
| 615 | 615 | } |
| 616 | 616 | return "DATE_FORMAT($string,$format)"; |
| 617 | 617 | } |
| 618 | 618 | case 'ifnull': |
| 619 | - if(empty($additional_parameters) && !strstr($all_strings, ",")) { |
|
| 619 | + if (empty($additional_parameters) && !strstr($all_strings, ",")) { |
|
| 620 | 620 | $all_strings .= ",''"; |
| 621 | 621 | } |
| 622 | 622 | return "IFNULL($all_strings)"; |
@@ -635,7 +635,7 @@ discard block |
||
| 635 | 635 | case 'add_tz_offset' : |
| 636 | 636 | $getUserUTCOffset = $GLOBALS['timedate']->getUserUTCOffset(); |
| 637 | 637 | $operation = $getUserUTCOffset < 0 ? '-' : '+'; |
| 638 | - return $string . ' ' . $operation . ' INTERVAL ' . abs($getUserUTCOffset) . ' MINUTE'; |
|
| 638 | + return $string.' '.$operation.' INTERVAL '.abs($getUserUTCOffset).' MINUTE'; |
|
| 639 | 639 | case 'avg': |
| 640 | 640 | return "avg($string)"; |
| 641 | 641 | } |
@@ -676,15 +676,15 @@ discard block |
||
| 676 | 676 | */ |
| 677 | 677 | protected function isEngineEnabled($engine) |
| 678 | 678 | { |
| 679 | - if(!is_string($engine)) return false; |
|
| 679 | + if (!is_string($engine)) return false; |
|
| 680 | 680 | |
| 681 | 681 | $engine = strtoupper($engine); |
| 682 | 682 | |
| 683 | 683 | $r = $this->query("SHOW ENGINES"); |
| 684 | 684 | |
| 685 | - while ( $row = $this->fetchByAssoc($r) ) |
|
| 686 | - if ( strtoupper($row['Engine']) == $engine ) |
|
| 687 | - return ($row['Support']=='YES' || $row['Support']=='DEFAULT'); |
|
| 685 | + while ($row = $this->fetchByAssoc($r)) |
|
| 686 | + if (strtoupper($row['Engine']) == $engine) |
|
| 687 | + return ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT'); |
|
| 688 | 688 | |
| 689 | 689 | return false; |
| 690 | 690 | } |
@@ -712,9 +712,9 @@ discard block |
||
| 712 | 712 | */ |
| 713 | 713 | public function createTableSQLParams($tablename, $fieldDefs, $indices, $engine = null) |
| 714 | 714 | { |
| 715 | - if ( empty($engine) && isset($fieldDefs['engine'])) |
|
| 715 | + if (empty($engine) && isset($fieldDefs['engine'])) |
|
| 716 | 716 | $engine = $fieldDefs['engine']; |
| 717 | - if ( !$this->isEngineEnabled($engine) ) |
|
| 717 | + if (!$this->isEngineEnabled($engine)) |
|
| 718 | 718 | $engine = ''; |
| 719 | 719 | |
| 720 | 720 | $columns = $this->columnSQLRep($fieldDefs, false, $tablename); |
@@ -727,13 +727,13 @@ discard block |
||
| 727 | 727 | |
| 728 | 728 | // cn: bug 9873 - module tables do not get created in utf8 with assoc collation |
| 729 | 729 | $collation = $this->getOption('collation'); |
| 730 | - if(empty($collation)) { |
|
| 730 | + if (empty($collation)) { |
|
| 731 | 731 | $collation = 'utf8_general_ci'; |
| 732 | 732 | } |
| 733 | 733 | $sql = "CREATE TABLE $tablename ($columns $keys) CHARACTER SET utf8 COLLATE $collation"; |
| 734 | 734 | |
| 735 | 735 | if (!empty($engine)) |
| 736 | - $sql.= " ENGINE=$engine"; |
|
| 736 | + $sql .= " ENGINE=$engine"; |
|
| 737 | 737 | |
| 738 | 738 | return $sql; |
| 739 | 739 | } |
@@ -745,7 +745,7 @@ discard block |
||
| 745 | 745 | public function isTextType($type) |
| 746 | 746 | { |
| 747 | 747 | $type = $this->getColumnType(strtolower($type)); |
| 748 | - return in_array($type, array('blob','text','longblob', 'longtext')); |
|
| 748 | + return in_array($type, array('blob', 'text', 'longblob', 'longtext')); |
|
| 749 | 749 | } |
| 750 | 750 | |
| 751 | 751 | /** |
@@ -756,16 +756,16 @@ discard block |
||
| 756 | 756 | // always return as array for post-processing |
| 757 | 757 | $ref = parent::oneColumnSQLRep($fieldDef, $ignoreRequired, $table, true); |
| 758 | 758 | |
| 759 | - if ( $ref['colType'] == 'int' && !empty($fieldDef['len']) ) { |
|
| 759 | + if ($ref['colType'] == 'int' && !empty($fieldDef['len'])) { |
|
| 760 | 760 | $ref['colType'] .= "(".$fieldDef['len'].")"; |
| 761 | 761 | } |
| 762 | 762 | |
| 763 | 763 | // bug 22338 - don't set a default value on text or blob fields |
| 764 | - if ( isset($ref['default']) && |
|
| 764 | + if (isset($ref['default']) && |
|
| 765 | 765 | in_array($ref['colBaseType'], array('text', 'blob', 'longtext', 'longblob'))) |
| 766 | 766 | $ref['default'] = ''; |
| 767 | 767 | |
| 768 | - if ( $return_as_array ) |
|
| 768 | + if ($return_as_array) |
|
| 769 | 769 | return $ref; |
| 770 | 770 | else |
| 771 | 771 | return "{$ref['name']} {$ref['colType']} {$ref['default']} {$ref['required']} {$ref['auto_increment']}"; |
@@ -777,8 +777,8 @@ discard block |
||
| 777 | 777 | protected function changeColumnSQL($tablename, $fieldDefs, $action, $ignoreRequired = false) |
| 778 | 778 | { |
| 779 | 779 | $columns = array(); |
| 780 | - if ($this->isFieldArray($fieldDefs)){ |
|
| 781 | - foreach ($fieldDefs as $def){ |
|
| 780 | + if ($this->isFieldArray($fieldDefs)) { |
|
| 781 | + foreach ($fieldDefs as $def) { |
|
| 782 | 782 | if ($action == 'drop') |
| 783 | 783 | $columns[] = $def['name']; |
| 784 | 784 | else |
@@ -815,7 +815,7 @@ discard block |
||
| 815 | 815 | |
| 816 | 816 | $columns = array(); |
| 817 | 817 | foreach ($indices as $index) { |
| 818 | - if(!empty($index['db']) && $index['db'] != $this->dbType) |
|
| 818 | + if (!empty($index['db']) && $index['db'] != $this->dbType) |
|
| 819 | 819 | continue; |
| 820 | 820 | if (isset($index['source']) && $index['source'] != 'db') |
| 821 | 821 | continue; |
@@ -845,7 +845,7 @@ discard block |
||
| 845 | 845 | * that this can easily be fixed by referring to db dictionary |
| 846 | 846 | * to find the correct primary field name |
| 847 | 847 | */ |
| 848 | - if ( $alter_table ) |
|
| 848 | + if ($alter_table) |
|
| 849 | 849 | $columns[] = " INDEX $name ($fields)"; |
| 850 | 850 | else |
| 851 | 851 | $columns[] = " KEY $name ($fields)"; |
@@ -854,13 +854,13 @@ discard block |
||
| 854 | 854 | if ($this->full_text_indexing_installed()) |
| 855 | 855 | $columns[] = " FULLTEXT ($fields)"; |
| 856 | 856 | else |
| 857 | - $GLOBALS['log']->debug('MYISAM engine is not available/enabled, full-text indexes will be skipped. Skipping:',$name); |
|
| 857 | + $GLOBALS['log']->debug('MYISAM engine is not available/enabled, full-text indexes will be skipped. Skipping:', $name); |
|
| 858 | 858 | break; |
| 859 | 859 | } |
| 860 | 860 | } |
| 861 | 861 | $columns = implode(", $alter_action ", $columns); |
| 862 | - if(!empty($alter_action)){ |
|
| 863 | - $columns = $alter_action . ' '. $columns; |
|
| 862 | + if (!empty($alter_action)) { |
|
| 863 | + $columns = $alter_action.' '.$columns; |
|
| 864 | 864 | } |
| 865 | 865 | return $columns; |
| 866 | 866 | } |
@@ -882,7 +882,7 @@ discard block |
||
| 882 | 882 | public function setAutoIncrementStart($table, $field_name, $start_value) |
| 883 | 883 | { |
| 884 | 884 | $start_value = (int)$start_value; |
| 885 | - return $this->query( "ALTER TABLE $table AUTO_INCREMENT = $start_value;"); |
|
| 885 | + return $this->query("ALTER TABLE $table AUTO_INCREMENT = $start_value;"); |
|
| 886 | 886 | } |
| 887 | 887 | |
| 888 | 888 | /** |
@@ -911,18 +911,18 @@ discard block |
||
| 911 | 911 | $result = $this->query("SHOW INDEX FROM $tablename"); |
| 912 | 912 | |
| 913 | 913 | $indices = array(); |
| 914 | - while (($row=$this->fetchByAssoc($result)) !=null) { |
|
| 915 | - $index_type='index'; |
|
| 916 | - if ($row['Key_name'] =='PRIMARY') { |
|
| 917 | - $index_type='primary'; |
|
| 914 | + while (($row = $this->fetchByAssoc($result)) != null) { |
|
| 915 | + $index_type = 'index'; |
|
| 916 | + if ($row['Key_name'] == 'PRIMARY') { |
|
| 917 | + $index_type = 'primary'; |
|
| 918 | 918 | } |
| 919 | - elseif ( $row['Non_unique'] == '0' ) { |
|
| 920 | - $index_type='unique'; |
|
| 919 | + elseif ($row['Non_unique'] == '0') { |
|
| 920 | + $index_type = 'unique'; |
|
| 921 | 921 | } |
| 922 | 922 | $name = strtolower($row['Key_name']); |
| 923 | - $indices[$name]['name']=$name; |
|
| 924 | - $indices[$name]['type']=$index_type; |
|
| 925 | - $indices[$name]['fields'][]=strtolower($row['Column_name']); |
|
| 923 | + $indices[$name]['name'] = $name; |
|
| 924 | + $indices[$name]['type'] = $index_type; |
|
| 925 | + $indices[$name]['fields'][] = strtolower($row['Column_name']); |
|
| 926 | 926 | } |
| 927 | 927 | return $indices; |
| 928 | 928 | } |
@@ -933,11 +933,11 @@ discard block |
||
| 933 | 933 | public function add_drop_constraint($table, $definition, $drop = false) |
| 934 | 934 | { |
| 935 | 935 | $type = $definition['type']; |
| 936 | - $fields = implode(',',$definition['fields']); |
|
| 936 | + $fields = implode(',', $definition['fields']); |
|
| 937 | 937 | $name = $definition['name']; |
| 938 | 938 | $sql = ''; |
| 939 | 939 | |
| 940 | - switch ($type){ |
|
| 940 | + switch ($type) { |
|
| 941 | 941 | // generic indices |
| 942 | 942 | case 'index': |
| 943 | 943 | case 'alternate_key': |
@@ -981,7 +981,7 @@ discard block |
||
| 981 | 981 | */ |
| 982 | 982 | public function fetchOne($sql, $dieOnError = false, $msg = '', $suppress = false) |
| 983 | 983 | { |
| 984 | - if(stripos($sql, ' LIMIT ') === false) { |
|
| 984 | + if (stripos($sql, ' LIMIT ') === false) { |
|
| 985 | 985 | // little optimization to just fetch one row |
| 986 | 986 | $sql .= " LIMIT 0,1"; |
| 987 | 987 | } |
@@ -1001,13 +1001,13 @@ discard block |
||
| 1001 | 1001 | */ |
| 1002 | 1002 | public function massageFieldDef(&$fieldDef, $tablename) |
| 1003 | 1003 | { |
| 1004 | - parent::massageFieldDef($fieldDef,$tablename); |
|
| 1004 | + parent::massageFieldDef($fieldDef, $tablename); |
|
| 1005 | 1005 | |
| 1006 | - if ( isset($fieldDef['default']) && |
|
| 1006 | + if (isset($fieldDef['default']) && |
|
| 1007 | 1007 | ($fieldDef['dbType'] == 'text' |
| 1008 | 1008 | || $fieldDef['dbType'] == 'blob' |
| 1009 | 1009 | || $fieldDef['dbType'] == 'longtext' |
| 1010 | - || $fieldDef['dbType'] == 'longblob' )) |
|
| 1010 | + || $fieldDef['dbType'] == 'longblob')) |
|
| 1011 | 1011 | unset($fieldDef['default']); |
| 1012 | 1012 | if ($fieldDef['dbType'] == 'uint') |
| 1013 | 1013 | $fieldDef['len'] = '10'; |
@@ -1015,22 +1015,22 @@ discard block |
||
| 1015 | 1015 | $fieldDef['len'] = '20'; |
| 1016 | 1016 | if ($fieldDef['dbType'] == 'bool') |
| 1017 | 1017 | $fieldDef['type'] = 'tinyint'; |
| 1018 | - if ($fieldDef['dbType'] == 'bool' && empty($fieldDef['default']) ) |
|
| 1018 | + if ($fieldDef['dbType'] == 'bool' && empty($fieldDef['default'])) |
|
| 1019 | 1019 | $fieldDef['default'] = '0'; |
| 1020 | - if (($fieldDef['dbType'] == 'varchar' || $fieldDef['dbType'] == 'enum') && empty($fieldDef['len']) ) |
|
| 1020 | + if (($fieldDef['dbType'] == 'varchar' || $fieldDef['dbType'] == 'enum') && empty($fieldDef['len'])) |
|
| 1021 | 1021 | $fieldDef['len'] = '255'; |
| 1022 | 1022 | if ($fieldDef['dbType'] == 'uint') |
| 1023 | 1023 | $fieldDef['len'] = '10'; |
| 1024 | - if ($fieldDef['dbType'] == 'int' && empty($fieldDef['len']) ) |
|
| 1024 | + if ($fieldDef['dbType'] == 'int' && empty($fieldDef['len'])) |
|
| 1025 | 1025 | $fieldDef['len'] = '11'; |
| 1026 | 1026 | |
| 1027 | - if($fieldDef['dbType'] == 'decimal') { |
|
| 1028 | - if(isset($fieldDef['len'])) { |
|
| 1029 | - if(strstr($fieldDef['len'], ",") === false) { |
|
| 1027 | + if ($fieldDef['dbType'] == 'decimal') { |
|
| 1028 | + if (isset($fieldDef['len'])) { |
|
| 1029 | + if (strstr($fieldDef['len'], ",") === false) { |
|
| 1030 | 1030 | $fieldDef['len'] .= ",0"; |
| 1031 | 1031 | } |
| 1032 | 1032 | } else { |
| 1033 | - $fieldDef['len'] = '10,0'; |
|
| 1033 | + $fieldDef['len'] = '10,0'; |
|
| 1034 | 1034 | } |
| 1035 | 1035 | } |
| 1036 | 1036 | } |
@@ -1050,8 +1050,8 @@ discard block |
||
| 1050 | 1050 | { |
| 1051 | 1051 | $sql = array(); |
| 1052 | 1052 | foreach ($indexes as $index) { |
| 1053 | - $name =$index['name']; |
|
| 1054 | - if($execute) { |
|
| 1053 | + $name = $index['name']; |
|
| 1054 | + if ($execute) { |
|
| 1055 | 1055 | unset(self::$index_descriptions[$tablename][$name]); |
| 1056 | 1056 | } |
| 1057 | 1057 | if ($index['type'] == 'primary') { |
@@ -1061,8 +1061,8 @@ discard block |
||
| 1061 | 1061 | } |
| 1062 | 1062 | } |
| 1063 | 1063 | if (!empty($sql)) { |
| 1064 | - $sql = "ALTER TABLE $tablename " . join(",", $sql) . ";"; |
|
| 1065 | - if($execute) |
|
| 1064 | + $sql = "ALTER TABLE $tablename ".join(",", $sql).";"; |
|
| 1065 | + if ($execute) |
|
| 1066 | 1066 | $this->query($sql); |
| 1067 | 1067 | } else { |
| 1068 | 1068 | $sql = ''; |
@@ -1088,7 +1088,7 @@ discard block |
||
| 1088 | 1088 | $q = "SHOW COLLATION LIKE 'utf8%'"; |
| 1089 | 1089 | $r = $this->query($q); |
| 1090 | 1090 | $res = array(); |
| 1091 | - while($a = $this->fetchByAssoc($r)) { |
|
| 1091 | + while ($a = $this->fetchByAssoc($r)) { |
|
| 1092 | 1092 | $res[] = $a['Collation']; |
| 1093 | 1093 | } |
| 1094 | 1094 | return $res; |
@@ -1108,13 +1108,13 @@ discard block |
||
| 1108 | 1108 | public function emptyValue($type) |
| 1109 | 1109 | { |
| 1110 | 1110 | $ctype = $this->getColumnType($type); |
| 1111 | - if($ctype == "datetime") { |
|
| 1111 | + if ($ctype == "datetime") { |
|
| 1112 | 1112 | return 'NULL'; |
| 1113 | 1113 | } |
| 1114 | - if($ctype == "date") { |
|
| 1114 | + if ($ctype == "date") { |
|
| 1115 | 1115 | return 'NULL'; |
| 1116 | 1116 | } |
| 1117 | - if($ctype == "time") { |
|
| 1117 | + if ($ctype == "time") { |
|
| 1118 | 1118 | return 'NULL'; |
| 1119 | 1119 | } |
| 1120 | 1120 | return parent::emptyValue($type); |
@@ -1126,13 +1126,13 @@ discard block |
||
| 1126 | 1126 | */ |
| 1127 | 1127 | public function lastDbError() |
| 1128 | 1128 | { |
| 1129 | - if($this->database) { |
|
| 1130 | - if(mysql_errno($this->database)) { |
|
| 1129 | + if ($this->database) { |
|
| 1130 | + if (mysql_errno($this->database)) { |
|
| 1131 | 1131 | return "MySQL error ".mysql_errno($this->database).": ".mysql_error($this->database); |
| 1132 | 1132 | } |
| 1133 | 1133 | } else { |
| 1134 | - $err = mysql_error(); |
|
| 1135 | - if($err) { |
|
| 1134 | + $err = mysql_error(); |
|
| 1135 | + if ($err) { |
|
| 1136 | 1136 | return $err; |
| 1137 | 1137 | } |
| 1138 | 1138 | } |
@@ -1145,7 +1145,7 @@ discard block |
||
| 1145 | 1145 | */ |
| 1146 | 1146 | protected function quoteTerm($term) |
| 1147 | 1147 | { |
| 1148 | - if(strpos($term, ' ') !== false) { |
|
| 1148 | + if (strpos($term, ' ') !== false) { |
|
| 1149 | 1149 | return '"'.$term.'"'; |
| 1150 | 1150 | } |
| 1151 | 1151 | return $term; |
@@ -1161,16 +1161,16 @@ discard block |
||
| 1161 | 1161 | public function getFulltextQuery($field, $terms, $must_terms = array(), $exclude_terms = array()) |
| 1162 | 1162 | { |
| 1163 | 1163 | $condition = array(); |
| 1164 | - foreach($terms as $term) { |
|
| 1164 | + foreach ($terms as $term) { |
|
| 1165 | 1165 | $condition[] = $this->quoteTerm($term); |
| 1166 | 1166 | } |
| 1167 | - foreach($must_terms as $term) { |
|
| 1167 | + foreach ($must_terms as $term) { |
|
| 1168 | 1168 | $condition[] = "+".$this->quoteTerm($term); |
| 1169 | 1169 | } |
| 1170 | - foreach($exclude_terms as $term) { |
|
| 1170 | + foreach ($exclude_terms as $term) { |
|
| 1171 | 1171 | $condition[] = "-".$this->quoteTerm($term); |
| 1172 | 1172 | } |
| 1173 | - $condition = $this->quoted(join(" ",$condition)); |
|
| 1173 | + $condition = $this->quoted(join(" ", $condition)); |
|
| 1174 | 1174 | return "MATCH($field) AGAINST($condition IN BOOLEAN MODE)"; |
| 1175 | 1175 | } |
| 1176 | 1176 | |
@@ -1182,7 +1182,7 @@ discard block |
||
| 1182 | 1182 | { |
| 1183 | 1183 | $charsets = array(); |
| 1184 | 1184 | $res = $this->query("show variables like 'character\\_set\\_%'"); |
| 1185 | - while($row = $this->fetchByAssoc($res)) { |
|
| 1185 | + while ($row = $this->fetchByAssoc($res)) { |
|
| 1186 | 1186 | $charsets[$row['Variable_name']] = $row['Value']; |
| 1187 | 1187 | } |
| 1188 | 1188 | return $charsets; |
@@ -1192,7 +1192,7 @@ discard block |
||
| 1192 | 1192 | { |
| 1193 | 1193 | $charsets = $this->getCharsetInfo(); |
| 1194 | 1194 | $charset_str = array(); |
| 1195 | - foreach($charsets as $name => $value) { |
|
| 1195 | + foreach ($charsets as $name => $value) { |
|
| 1196 | 1196 | $charset_str[] = "$name = $value"; |
| 1197 | 1197 | } |
| 1198 | 1198 | return array( |
@@ -1214,18 +1214,18 @@ discard block |
||
| 1214 | 1214 | { |
| 1215 | 1215 | $this->log->debug("creating temp table for [$table]..."); |
| 1216 | 1216 | $result = $this->query("SHOW CREATE TABLE {$table}"); |
| 1217 | - if(empty($result)) { |
|
| 1217 | + if (empty($result)) { |
|
| 1218 | 1218 | return false; |
| 1219 | 1219 | } |
| 1220 | 1220 | $row = $this->fetchByAssoc($result); |
| 1221 | - if(empty($row) || empty($row['Create Table'])) { |
|
| 1221 | + if (empty($row) || empty($row['Create Table'])) { |
|
| 1222 | 1222 | return false; |
| 1223 | 1223 | } |
| 1224 | 1224 | $create = $row['Create Table']; |
| 1225 | 1225 | // rewrite DDL with _temp name |
| 1226 | 1226 | $tempTableQuery = str_replace("CREATE TABLE `{$table}`", "CREATE TABLE `{$table}__uw_temp`", $create); |
| 1227 | 1227 | $r2 = $this->query($tempTableQuery); |
| 1228 | - if(empty($r2)) { |
|
| 1228 | + if (empty($r2)) { |
|
| 1229 | 1229 | return false; |
| 1230 | 1230 | } |
| 1231 | 1231 | |
@@ -1247,11 +1247,11 @@ discard block |
||
| 1247 | 1247 | $this->log->debug("verifying ALTER TABLE"); |
| 1248 | 1248 | // Skipping ALTER TABLE [table] DROP PRIMARY KEY because primary keys are not being copied |
| 1249 | 1249 | // over to the temp tables |
| 1250 | - if(strpos(strtoupper($query), 'DROP PRIMARY KEY') !== false) { |
|
| 1250 | + if (strpos(strtoupper($query), 'DROP PRIMARY KEY') !== false) { |
|
| 1251 | 1251 | $this->log->debug("Skipping DROP PRIMARY KEY"); |
| 1252 | 1252 | return ''; |
| 1253 | 1253 | } |
| 1254 | - if(!$this->makeTempTableCopy($table)) { |
|
| 1254 | + if (!$this->makeTempTableCopy($table)) { |
|
| 1255 | 1255 | return 'Could not create temp table copy'; |
| 1256 | 1256 | } |
| 1257 | 1257 | |
@@ -1259,7 +1259,7 @@ discard block |
||
| 1259 | 1259 | $this->log->debug('testing query: ['.$query.']'); |
| 1260 | 1260 | $tempTableTestQuery = str_replace("ALTER TABLE `{$table}`", "ALTER TABLE `{$table}__uw_temp`", $query); |
| 1261 | 1261 | if (strpos($tempTableTestQuery, 'idx') === false) { |
| 1262 | - if(strpos($tempTableTestQuery, '__uw_temp') === false) { |
|
| 1262 | + if (strpos($tempTableTestQuery, '__uw_temp') === false) { |
|
| 1263 | 1263 | return 'Could not use a temp table to test query!'; |
| 1264 | 1264 | } |
| 1265 | 1265 | |
@@ -1272,7 +1272,7 @@ discard block |
||
| 1272 | 1272 | $this->query($tempTableTestQuery_idx, false, "Preflight Failed for: {$query}"); |
| 1273 | 1273 | } |
| 1274 | 1274 | $mysqlError = $this->getL(); |
| 1275 | - if(!empty($mysqlError)) { |
|
| 1275 | + if (!empty($mysqlError)) { |
|
| 1276 | 1276 | return $mysqlError; |
| 1277 | 1277 | } |
| 1278 | 1278 | $this->dropTableName("{$table}__uw_temp"); |
@@ -1284,13 +1284,13 @@ discard block |
||
| 1284 | 1284 | { |
| 1285 | 1285 | $this->log->debug("verifying $querytype statement"); |
| 1286 | 1286 | |
| 1287 | - if(!$this->makeTempTableCopy($table)) { |
|
| 1287 | + if (!$this->makeTempTableCopy($table)) { |
|
| 1288 | 1288 | return 'Could not create temp table copy'; |
| 1289 | 1289 | } |
| 1290 | 1290 | // test the query on the test table |
| 1291 | 1291 | $this->log->debug('testing query: ['.$query.']'); |
| 1292 | 1292 | $tempTableTestQuery = str_replace("$querytype `{$table}`", "$querytype `{$table}__uw_temp`", $query); |
| 1293 | - if(strpos($tempTableTestQuery, '__uw_temp') === false) { |
|
| 1293 | + if (strpos($tempTableTestQuery, '__uw_temp') === false) { |
|
| 1294 | 1294 | return 'Could not use a temp table to test query!'; |
| 1295 | 1295 | } |
| 1296 | 1296 | |
@@ -1370,11 +1370,11 @@ discard block |
||
| 1370 | 1370 | public function userExists($username) |
| 1371 | 1371 | { |
| 1372 | 1372 | $db = $this->getOne("SELECT DATABASE()"); |
| 1373 | - if(!$this->selectDb("mysql")) { |
|
| 1373 | + if (!$this->selectDb("mysql")) { |
|
| 1374 | 1374 | return false; |
| 1375 | 1375 | } |
| 1376 | 1376 | $user = $this->getOne("select count(*) from user where user = ".$this->quoted($username)); |
| 1377 | - if(!$this->selectDb($db)) { |
|
| 1377 | + if (!$this->selectDb($db)) { |
|
| 1378 | 1378 | $this->checkError("Cannot select database $db", true); |
| 1379 | 1379 | } |
| 1380 | 1380 | return !empty($user); |
@@ -1396,7 +1396,7 @@ discard block |
||
| 1396 | 1396 | IDENTIFIED BY '{$qpassword}';", true); |
| 1397 | 1397 | |
| 1398 | 1398 | $this->query("SET PASSWORD FOR \"{$user}\"@\"{$host_name}\" = password('{$qpassword}');", true); |
| 1399 | - if($host_name != 'localhost') { |
|
| 1399 | + if ($host_name != 'localhost') { |
|
| 1400 | 1400 | $this->createDbUser($database_name, "localhost", $user, $password); |
| 1401 | 1401 | } |
| 1402 | 1402 | } |
@@ -1442,10 +1442,10 @@ discard block |
||
| 1442 | 1442 | public function canInstall() |
| 1443 | 1443 | { |
| 1444 | 1444 | $db_version = $this->version(); |
| 1445 | - if(empty($db_version)) { |
|
| 1445 | + if (empty($db_version)) { |
|
| 1446 | 1446 | return array('ERR_DB_VERSION_FAILURE'); |
| 1447 | 1447 | } |
| 1448 | - if(version_compare($db_version, '4.1.2') < 0) { |
|
| 1448 | + if (version_compare($db_version, '4.1.2') < 0) { |
|
| 1449 | 1449 | return array('ERR_DB_MYSQL_VERSION', $db_version); |
| 1450 | 1450 | } |
| 1451 | 1451 | return true; |
@@ -189,8 +189,9 @@ discard block |
||
| 189 | 189 | $GLOBALS['log']->info('Query Execution Time:'.$this->query_time); |
| 190 | 190 | |
| 191 | 191 | |
| 192 | - if($keepResult) |
|
| 193 | - $this->lastResult = $result; |
|
| 192 | + if($keepResult) { |
|
| 193 | + $this->lastResult = $result; |
|
| 194 | + } |
|
| 194 | 195 | |
| 195 | 196 | $this->checkError($msg.' Query Failed:' . $sql . '::', $dieOnError); |
| 196 | 197 | return $result; |
@@ -240,8 +241,9 @@ discard block |
||
| 240 | 241 | */ |
| 241 | 242 | protected function freeDbResult($dbResult) |
| 242 | 243 | { |
| 243 | - if(!empty($dbResult)) |
|
| 244 | - mysql_free_result($dbResult); |
|
| 244 | + if(!empty($dbResult)) { |
|
| 245 | + mysql_free_result($dbResult); |
|
| 246 | + } |
|
| 245 | 247 | } |
| 246 | 248 | |
| 247 | 249 | |
@@ -264,8 +266,9 @@ discard block |
||
| 264 | 266 | { |
| 265 | 267 | $start = (int)$start; |
| 266 | 268 | $count = (int)$count; |
| 267 | - if ($start < 0) |
|
| 268 | - $start = 0; |
|
| 269 | + if ($start < 0) { |
|
| 270 | + $start = 0; |
|
| 271 | + } |
|
| 269 | 272 | $GLOBALS['log']->debug('Limit Query:' . $sql. ' Start: ' .$start . ' count: ' . $count); |
| 270 | 273 | |
| 271 | 274 | $sql = "$sql LIMIT $start,$count"; |
@@ -290,21 +293,27 @@ discard block |
||
| 290 | 293 | $result = $this->query('EXPLAIN ' . $sql); |
| 291 | 294 | $badQuery = array(); |
| 292 | 295 | while ($row = $this->fetchByAssoc($result)) { |
| 293 | - if (empty($row['table'])) |
|
| 294 | - continue; |
|
| 296 | + if (empty($row['table'])) { |
|
| 297 | + continue; |
|
| 298 | + } |
|
| 295 | 299 | $badQuery[$row['table']] = ''; |
| 296 | - if (strtoupper($row['type']) == 'ALL') |
|
| 297 | - $badQuery[$row['table']] .= ' Full Table Scan;'; |
|
| 298 | - if (empty($row['key'])) |
|
| 299 | - $badQuery[$row['table']] .= ' No Index Key Used;'; |
|
| 300 | - if (!empty($row['Extra']) && substr_count($row['Extra'], 'Using filesort') > 0) |
|
| 301 | - $badQuery[$row['table']] .= ' Using FileSort;'; |
|
| 302 | - if (!empty($row['Extra']) && substr_count($row['Extra'], 'Using temporary') > 0) |
|
| 303 | - $badQuery[$row['table']] .= ' Using Temporary Table;'; |
|
| 300 | + if (strtoupper($row['type']) == 'ALL') { |
|
| 301 | + $badQuery[$row['table']] .= ' Full Table Scan;'; |
|
| 302 | + } |
|
| 303 | + if (empty($row['key'])) { |
|
| 304 | + $badQuery[$row['table']] .= ' No Index Key Used;'; |
|
| 305 | + } |
|
| 306 | + if (!empty($row['Extra']) && substr_count($row['Extra'], 'Using filesort') > 0) { |
|
| 307 | + $badQuery[$row['table']] .= ' Using FileSort;'; |
|
| 308 | + } |
|
| 309 | + if (!empty($row['Extra']) && substr_count($row['Extra'], 'Using temporary') > 0) { |
|
| 310 | + $badQuery[$row['table']] .= ' Using Temporary Table;'; |
|
| 311 | + } |
|
| 304 | 312 | } |
| 305 | 313 | |
| 306 | - if ( empty($badQuery) ) |
|
| 307 | - return true; |
|
| 314 | + if ( empty($badQuery) ) { |
|
| 315 | + return true; |
|
| 316 | + } |
|
| 308 | 317 | |
| 309 | 318 | foreach($badQuery as $table=>$data ){ |
| 310 | 319 | if(!empty($data)){ |
@@ -312,8 +321,7 @@ discard block |
||
| 312 | 321 | if(!empty($GLOBALS['sugar_config']['check_query_log'])){ |
| 313 | 322 | $GLOBALS['log']->fatal($sql); |
| 314 | 323 | $GLOBALS['log']->fatal('CHECK QUERY:' .$warning); |
| 315 | - } |
|
| 316 | - else{ |
|
| 324 | + } else{ |
|
| 317 | 325 | $GLOBALS['log']->warn('CHECK QUERY:' .$warning); |
| 318 | 326 | } |
| 319 | 327 | } |
@@ -337,14 +345,18 @@ discard block |
||
| 337 | 345 | $matches = array(); |
| 338 | 346 | preg_match_all('/(\w+)(?:\(([0-9]+,?[0-9]*)\)|)( unsigned)?/i', $row['Type'], $matches); |
| 339 | 347 | $columns[$name]['type']=strtolower($matches[1][0]); |
| 340 | - if ( isset($matches[2][0]) && in_array(strtolower($matches[1][0]),array('varchar','char','varchar2','int','decimal','float')) ) |
|
| 341 | - $columns[$name]['len']=strtolower($matches[2][0]); |
|
| 342 | - if ( stristr($row['Extra'],'auto_increment') ) |
|
| 343 | - $columns[$name]['auto_increment'] = '1'; |
|
| 344 | - if ($row['Null'] == 'NO' && !stristr($row['Key'],'PRI')) |
|
| 345 | - $columns[$name]['required'] = 'true'; |
|
| 346 | - if (!empty($row['Default']) ) |
|
| 347 | - $columns[$name]['default'] = $row['Default']; |
|
| 348 | + if ( isset($matches[2][0]) && in_array(strtolower($matches[1][0]),array('varchar','char','varchar2','int','decimal','float')) ) { |
|
| 349 | + $columns[$name]['len']=strtolower($matches[2][0]); |
|
| 350 | + } |
|
| 351 | + if ( stristr($row['Extra'],'auto_increment') ) { |
|
| 352 | + $columns[$name]['auto_increment'] = '1'; |
|
| 353 | + } |
|
| 354 | + if ($row['Null'] == 'NO' && !stristr($row['Key'],'PRI')) { |
|
| 355 | + $columns[$name]['required'] = 'true'; |
|
| 356 | + } |
|
| 357 | + if (!empty($row['Default']) ) { |
|
| 358 | + $columns[$name]['default'] = $row['Default']; |
|
| 359 | + } |
|
| 348 | 360 | } |
| 349 | 361 | return $columns; |
| 350 | 362 | } |
@@ -356,17 +368,20 @@ discard block |
||
| 356 | 368 | { |
| 357 | 369 | $field_array = array(); |
| 358 | 370 | |
| 359 | - if(empty($result)) |
|
| 360 | - return 0; |
|
| 371 | + if(empty($result)) { |
|
| 372 | + return 0; |
|
| 373 | + } |
|
| 361 | 374 | |
| 362 | 375 | $fields = mysql_num_fields($result); |
| 363 | 376 | for ($i=0; $i < $fields; $i++) { |
| 364 | 377 | $meta = mysql_fetch_field($result, $i); |
| 365 | - if (!$meta) |
|
| 366 | - return array(); |
|
| 378 | + if (!$meta) { |
|
| 379 | + return array(); |
|
| 380 | + } |
|
| 367 | 381 | |
| 368 | - if($make_lower_case == true) |
|
| 369 | - $meta->name = strtolower($meta->name); |
|
| 382 | + if($make_lower_case == true) { |
|
| 383 | + $meta->name = strtolower($meta->name); |
|
| 384 | + } |
|
| 370 | 385 | |
| 371 | 386 | $field_array[] = $meta->name; |
| 372 | 387 | } |
@@ -379,7 +394,9 @@ discard block |
||
| 379 | 394 | */ |
| 380 | 395 | public function fetchRow($result) |
| 381 | 396 | { |
| 382 | - if (empty($result)) return false; |
|
| 397 | + if (empty($result)) { |
|
| 398 | + return false; |
|
| 399 | + } |
|
| 383 | 400 | |
| 384 | 401 | return mysql_fetch_assoc($result); |
| 385 | 402 | } |
@@ -423,7 +440,9 @@ discard block |
||
| 423 | 440 | |
| 424 | 441 | if ($this->getDatabase()) { |
| 425 | 442 | $result = $this->query("SHOW TABLES LIKE ".$this->quoted($tableName)); |
| 426 | - if(empty($result)) return false; |
|
| 443 | + if(empty($result)) { |
|
| 444 | + return false; |
|
| 445 | + } |
|
| 427 | 446 | $row = $this->fetchByAssoc($result); |
| 428 | 447 | return !empty($row); |
| 429 | 448 | } |
@@ -478,8 +497,9 @@ discard block |
||
| 478 | 497 | { |
| 479 | 498 | global $sugar_config; |
| 480 | 499 | |
| 481 | - if(is_null($configOptions)) |
|
| 482 | - $configOptions = $sugar_config['dbconfig']; |
|
| 500 | + if(is_null($configOptions)) { |
|
| 501 | + $configOptions = $sugar_config['dbconfig']; |
|
| 502 | + } |
|
| 483 | 503 | |
| 484 | 504 | if ($this->getOption('persistent')) { |
| 485 | 505 | $this->database = @mysql_pconnect( |
@@ -532,8 +552,9 @@ discard block |
||
| 532 | 552 | } |
| 533 | 553 | mysql_query($names, $this->database); |
| 534 | 554 | |
| 535 | - if(!$this->checkError('Could Not Connect:', $dieOnError)) |
|
| 536 | - $GLOBALS['log']->info("connected to db"); |
|
| 555 | + if(!$this->checkError('Could Not Connect:', $dieOnError)) { |
|
| 556 | + $GLOBALS['log']->info("connected to db"); |
|
| 557 | + } |
|
| 537 | 558 | $this->connectOptions = $configOptions; |
| 538 | 559 | |
| 539 | 560 | $GLOBALS['log']->info("Connect:".$this->database); |
@@ -550,8 +571,9 @@ discard block |
||
| 550 | 571 | { |
| 551 | 572 | $sql = parent::repairTableParams($tablename,$fielddefs,$indices,false,$engine); |
| 552 | 573 | |
| 553 | - if ( $sql == '' ) |
|
| 554 | - return ''; |
|
| 574 | + if ( $sql == '' ) { |
|
| 575 | + return ''; |
|
| 576 | + } |
|
| 555 | 577 | |
| 556 | 578 | if ( stristr($sql,'create table') ) |
| 557 | 579 | { |
@@ -578,8 +600,9 @@ discard block |
||
| 578 | 600 | $sql = str_replace("\n","",$sql); |
| 579 | 601 | $sql = "ALTER TABLE $tablename $sql"; |
| 580 | 602 | |
| 581 | - if ( $execute ) |
|
| 582 | - $this->query($sql,'Error with MySQL repair table'); |
|
| 603 | + if ( $execute ) { |
|
| 604 | + $this->query($sql,'Error with MySQL repair table'); |
|
| 605 | + } |
|
| 583 | 606 | |
| 584 | 607 | // and re-add the comments at the beginning |
| 585 | 608 | $sql = implode("\n",$commentBlocks) . "\n". $sql . "\n"; |
@@ -676,15 +699,18 @@ discard block |
||
| 676 | 699 | */ |
| 677 | 700 | protected function isEngineEnabled($engine) |
| 678 | 701 | { |
| 679 | - if(!is_string($engine)) return false; |
|
| 702 | + if(!is_string($engine)) { |
|
| 703 | + return false; |
|
| 704 | + } |
|
| 680 | 705 | |
| 681 | 706 | $engine = strtoupper($engine); |
| 682 | 707 | |
| 683 | 708 | $r = $this->query("SHOW ENGINES"); |
| 684 | 709 | |
| 685 | - while ( $row = $this->fetchByAssoc($r) ) |
|
| 686 | - if ( strtoupper($row['Engine']) == $engine ) |
|
| 710 | + while ( $row = $this->fetchByAssoc($r) ) { |
|
| 711 | + if ( strtoupper($row['Engine']) == $engine ) |
|
| 687 | 712 | return ($row['Support']=='YES' || $row['Support']=='DEFAULT'); |
| 713 | + } |
|
| 688 | 714 | |
| 689 | 715 | return false; |
| 690 | 716 | } |
@@ -712,18 +738,22 @@ discard block |
||
| 712 | 738 | */ |
| 713 | 739 | public function createTableSQLParams($tablename, $fieldDefs, $indices, $engine = null) |
| 714 | 740 | { |
| 715 | - if ( empty($engine) && isset($fieldDefs['engine'])) |
|
| 716 | - $engine = $fieldDefs['engine']; |
|
| 717 | - if ( !$this->isEngineEnabled($engine) ) |
|
| 718 | - $engine = ''; |
|
| 741 | + if ( empty($engine) && isset($fieldDefs['engine'])) { |
|
| 742 | + $engine = $fieldDefs['engine']; |
|
| 743 | + } |
|
| 744 | + if ( !$this->isEngineEnabled($engine) ) { |
|
| 745 | + $engine = ''; |
|
| 746 | + } |
|
| 719 | 747 | |
| 720 | 748 | $columns = $this->columnSQLRep($fieldDefs, false, $tablename); |
| 721 | - if (empty($columns)) |
|
| 722 | - return false; |
|
| 749 | + if (empty($columns)) { |
|
| 750 | + return false; |
|
| 751 | + } |
|
| 723 | 752 | |
| 724 | 753 | $keys = $this->keysSQL($indices); |
| 725 | - if (!empty($keys)) |
|
| 726 | - $keys = ",$keys"; |
|
| 754 | + if (!empty($keys)) { |
|
| 755 | + $keys = ",$keys"; |
|
| 756 | + } |
|
| 727 | 757 | |
| 728 | 758 | // cn: bug 9873 - module tables do not get created in utf8 with assoc collation |
| 729 | 759 | $collation = $this->getOption('collation'); |
@@ -732,8 +762,9 @@ discard block |
||
| 732 | 762 | } |
| 733 | 763 | $sql = "CREATE TABLE $tablename ($columns $keys) CHARACTER SET utf8 COLLATE $collation"; |
| 734 | 764 | |
| 735 | - if (!empty($engine)) |
|
| 736 | - $sql.= " ENGINE=$engine"; |
|
| 765 | + if (!empty($engine)) { |
|
| 766 | + $sql.= " ENGINE=$engine"; |
|
| 767 | + } |
|
| 737 | 768 | |
| 738 | 769 | return $sql; |
| 739 | 770 | } |
@@ -762,13 +793,15 @@ discard block |
||
| 762 | 793 | |
| 763 | 794 | // bug 22338 - don't set a default value on text or blob fields |
| 764 | 795 | if ( isset($ref['default']) && |
| 765 | - in_array($ref['colBaseType'], array('text', 'blob', 'longtext', 'longblob'))) |
|
| 766 | - $ref['default'] = ''; |
|
| 796 | + in_array($ref['colBaseType'], array('text', 'blob', 'longtext', 'longblob'))) { |
|
| 797 | + $ref['default'] = ''; |
|
| 798 | + } |
|
| 767 | 799 | |
| 768 | - if ( $return_as_array ) |
|
| 769 | - return $ref; |
|
| 770 | - else |
|
| 771 | - return "{$ref['name']} {$ref['colType']} {$ref['default']} {$ref['required']} {$ref['auto_increment']}"; |
|
| 800 | + if ( $return_as_array ) { |
|
| 801 | + return $ref; |
|
| 802 | + } else { |
|
| 803 | + return "{$ref['name']} {$ref['colType']} {$ref['default']} {$ref['required']} {$ref['auto_increment']}"; |
|
| 804 | + } |
|
| 772 | 805 | } |
| 773 | 806 | |
| 774 | 807 | /** |
@@ -779,16 +812,18 @@ discard block |
||
| 779 | 812 | $columns = array(); |
| 780 | 813 | if ($this->isFieldArray($fieldDefs)){ |
| 781 | 814 | foreach ($fieldDefs as $def){ |
| 782 | - if ($action == 'drop') |
|
| 783 | - $columns[] = $def['name']; |
|
| 784 | - else |
|
| 785 | - $columns[] = $this->oneColumnSQLRep($def, $ignoreRequired); |
|
| 815 | + if ($action == 'drop') { |
|
| 816 | + $columns[] = $def['name']; |
|
| 817 | + } else { |
|
| 818 | + $columns[] = $this->oneColumnSQLRep($def, $ignoreRequired); |
|
| 819 | + } |
|
| 786 | 820 | } |
| 787 | 821 | } else { |
| 788 | - if ($action == 'drop') |
|
| 789 | - $columns[] = $fieldDefs['name']; |
|
| 790 | - else |
|
| 791 | - $columns[] = $this->oneColumnSQLRep($fieldDefs); |
|
| 822 | + if ($action == 'drop') { |
|
| 823 | + $columns[] = $fieldDefs['name']; |
|
| 824 | + } else { |
|
| 825 | + $columns[] = $this->oneColumnSQLRep($fieldDefs); |
|
| 826 | + } |
|
| 792 | 827 | } |
| 793 | 828 | |
| 794 | 829 | return "ALTER TABLE $tablename $action COLUMN ".implode(",$action column ", $columns); |
@@ -810,23 +845,27 @@ discard block |
||
| 810 | 845 | { |
| 811 | 846 | // check if the passed value is an array of fields. |
| 812 | 847 | // if not, convert it into an array |
| 813 | - if (!$this->isFieldArray($indices)) |
|
| 814 | - $indices[] = $indices; |
|
| 848 | + if (!$this->isFieldArray($indices)) { |
|
| 849 | + $indices[] = $indices; |
|
| 850 | + } |
|
| 815 | 851 | |
| 816 | 852 | $columns = array(); |
| 817 | 853 | foreach ($indices as $index) { |
| 818 | - if(!empty($index['db']) && $index['db'] != $this->dbType) |
|
| 819 | - continue; |
|
| 820 | - if (isset($index['source']) && $index['source'] != 'db') |
|
| 821 | - continue; |
|
| 854 | + if(!empty($index['db']) && $index['db'] != $this->dbType) { |
|
| 855 | + continue; |
|
| 856 | + } |
|
| 857 | + if (isset($index['source']) && $index['source'] != 'db') { |
|
| 858 | + continue; |
|
| 859 | + } |
|
| 822 | 860 | |
| 823 | 861 | $type = $index['type']; |
| 824 | 862 | $name = $index['name']; |
| 825 | 863 | |
| 826 | - if (is_array($index['fields'])) |
|
| 827 | - $fields = implode(", ", $index['fields']); |
|
| 828 | - else |
|
| 829 | - $fields = $index['fields']; |
|
| 864 | + if (is_array($index['fields'])) { |
|
| 865 | + $fields = implode(", ", $index['fields']); |
|
| 866 | + } else { |
|
| 867 | + $fields = $index['fields']; |
|
| 868 | + } |
|
| 830 | 869 | |
| 831 | 870 | switch ($type) { |
| 832 | 871 | case 'unique': |
@@ -845,16 +884,18 @@ discard block |
||
| 845 | 884 | * that this can easily be fixed by referring to db dictionary |
| 846 | 885 | * to find the correct primary field name |
| 847 | 886 | */ |
| 848 | - if ( $alter_table ) |
|
| 849 | - $columns[] = " INDEX $name ($fields)"; |
|
| 850 | - else |
|
| 851 | - $columns[] = " KEY $name ($fields)"; |
|
| 887 | + if ( $alter_table ) { |
|
| 888 | + $columns[] = " INDEX $name ($fields)"; |
|
| 889 | + } else { |
|
| 890 | + $columns[] = " KEY $name ($fields)"; |
|
| 891 | + } |
|
| 852 | 892 | break; |
| 853 | 893 | case 'fulltext': |
| 854 | - if ($this->full_text_indexing_installed()) |
|
| 855 | - $columns[] = " FULLTEXT ($fields)"; |
|
| 856 | - else |
|
| 857 | - $GLOBALS['log']->debug('MYISAM engine is not available/enabled, full-text indexes will be skipped. Skipping:',$name); |
|
| 894 | + if ($this->full_text_indexing_installed()) { |
|
| 895 | + $columns[] = " FULLTEXT ($fields)"; |
|
| 896 | + } else { |
|
| 897 | + $GLOBALS['log']->debug('MYISAM engine is not available/enabled, full-text indexes will be skipped. Skipping:',$name); |
|
| 898 | + } |
|
| 858 | 899 | break; |
| 859 | 900 | } |
| 860 | 901 | } |
@@ -896,8 +937,9 @@ discard block |
||
| 896 | 937 | { |
| 897 | 938 | $result = $this->query("SHOW TABLE STATUS LIKE '$table'"); |
| 898 | 939 | $row = $this->fetchByAssoc($result); |
| 899 | - if (!empty($row['Auto_increment'])) |
|
| 900 | - return $row['Auto_increment']; |
|
| 940 | + if (!empty($row['Auto_increment'])) { |
|
| 941 | + return $row['Auto_increment']; |
|
| 942 | + } |
|
| 901 | 943 | |
| 902 | 944 | return ""; |
| 903 | 945 | } |
@@ -915,8 +957,7 @@ discard block |
||
| 915 | 957 | $index_type='index'; |
| 916 | 958 | if ($row['Key_name'] =='PRIMARY') { |
| 917 | 959 | $index_type='primary'; |
| 918 | - } |
|
| 919 | - elseif ( $row['Non_unique'] == '0' ) { |
|
| 960 | + } elseif ( $row['Non_unique'] == '0' ) { |
|
| 920 | 961 | $index_type='unique'; |
| 921 | 962 | } |
| 922 | 963 | $name = strtolower($row['Key_name']); |
@@ -942,29 +983,33 @@ discard block |
||
| 942 | 983 | case 'index': |
| 943 | 984 | case 'alternate_key': |
| 944 | 985 | case 'clustered': |
| 945 | - if ($drop) |
|
| 946 | - $sql = "ALTER TABLE {$table} DROP INDEX {$name} "; |
|
| 947 | - else |
|
| 948 | - $sql = "ALTER TABLE {$table} ADD INDEX {$name} ({$fields})"; |
|
| 986 | + if ($drop) { |
|
| 987 | + $sql = "ALTER TABLE {$table} DROP INDEX {$name} "; |
|
| 988 | + } else { |
|
| 989 | + $sql = "ALTER TABLE {$table} ADD INDEX {$name} ({$fields})"; |
|
| 990 | + } |
|
| 949 | 991 | break; |
| 950 | 992 | // constraints as indices |
| 951 | 993 | case 'unique': |
| 952 | - if ($drop) |
|
| 953 | - $sql = "ALTER TABLE {$table} DROP INDEX $name"; |
|
| 954 | - else |
|
| 955 | - $sql = "ALTER TABLE {$table} ADD CONSTRAINT UNIQUE {$name} ({$fields})"; |
|
| 994 | + if ($drop) { |
|
| 995 | + $sql = "ALTER TABLE {$table} DROP INDEX $name"; |
|
| 996 | + } else { |
|
| 997 | + $sql = "ALTER TABLE {$table} ADD CONSTRAINT UNIQUE {$name} ({$fields})"; |
|
| 998 | + } |
|
| 956 | 999 | break; |
| 957 | 1000 | case 'primary': |
| 958 | - if ($drop) |
|
| 959 | - $sql = "ALTER TABLE {$table} DROP PRIMARY KEY"; |
|
| 960 | - else |
|
| 961 | - $sql = "ALTER TABLE {$table} ADD CONSTRAINT PRIMARY KEY ({$fields})"; |
|
| 1001 | + if ($drop) { |
|
| 1002 | + $sql = "ALTER TABLE {$table} DROP PRIMARY KEY"; |
|
| 1003 | + } else { |
|
| 1004 | + $sql = "ALTER TABLE {$table} ADD CONSTRAINT PRIMARY KEY ({$fields})"; |
|
| 1005 | + } |
|
| 962 | 1006 | break; |
| 963 | 1007 | case 'foreign': |
| 964 | - if ($drop) |
|
| 965 | - $sql = "ALTER TABLE {$table} DROP FOREIGN KEY ({$fields})"; |
|
| 966 | - else |
|
| 967 | - $sql = "ALTER TABLE {$table} ADD CONSTRAINT FOREIGN KEY {$name} ({$fields}) REFERENCES {$definition['foreignTable']}({$definition['foreignField']})"; |
|
| 1008 | + if ($drop) { |
|
| 1009 | + $sql = "ALTER TABLE {$table} DROP FOREIGN KEY ({$fields})"; |
|
| 1010 | + } else { |
|
| 1011 | + $sql = "ALTER TABLE {$table} ADD CONSTRAINT FOREIGN KEY {$name} ({$fields}) REFERENCES {$definition['foreignTable']}({$definition['foreignField']})"; |
|
| 1012 | + } |
|
| 968 | 1013 | break; |
| 969 | 1014 | } |
| 970 | 1015 | return $sql; |
@@ -1007,22 +1052,30 @@ discard block |
||
| 1007 | 1052 | ($fieldDef['dbType'] == 'text' |
| 1008 | 1053 | || $fieldDef['dbType'] == 'blob' |
| 1009 | 1054 | || $fieldDef['dbType'] == 'longtext' |
| 1010 | - || $fieldDef['dbType'] == 'longblob' )) |
|
| 1011 | - unset($fieldDef['default']); |
|
| 1012 | - if ($fieldDef['dbType'] == 'uint') |
|
| 1013 | - $fieldDef['len'] = '10'; |
|
| 1014 | - if ($fieldDef['dbType'] == 'ulong') |
|
| 1015 | - $fieldDef['len'] = '20'; |
|
| 1016 | - if ($fieldDef['dbType'] == 'bool') |
|
| 1017 | - $fieldDef['type'] = 'tinyint'; |
|
| 1018 | - if ($fieldDef['dbType'] == 'bool' && empty($fieldDef['default']) ) |
|
| 1019 | - $fieldDef['default'] = '0'; |
|
| 1020 | - if (($fieldDef['dbType'] == 'varchar' || $fieldDef['dbType'] == 'enum') && empty($fieldDef['len']) ) |
|
| 1021 | - $fieldDef['len'] = '255'; |
|
| 1022 | - if ($fieldDef['dbType'] == 'uint') |
|
| 1023 | - $fieldDef['len'] = '10'; |
|
| 1024 | - if ($fieldDef['dbType'] == 'int' && empty($fieldDef['len']) ) |
|
| 1025 | - $fieldDef['len'] = '11'; |
|
| 1055 | + || $fieldDef['dbType'] == 'longblob' )) { |
|
| 1056 | + unset($fieldDef['default']); |
|
| 1057 | + } |
|
| 1058 | + if ($fieldDef['dbType'] == 'uint') { |
|
| 1059 | + $fieldDef['len'] = '10'; |
|
| 1060 | + } |
|
| 1061 | + if ($fieldDef['dbType'] == 'ulong') { |
|
| 1062 | + $fieldDef['len'] = '20'; |
|
| 1063 | + } |
|
| 1064 | + if ($fieldDef['dbType'] == 'bool') { |
|
| 1065 | + $fieldDef['type'] = 'tinyint'; |
|
| 1066 | + } |
|
| 1067 | + if ($fieldDef['dbType'] == 'bool' && empty($fieldDef['default']) ) { |
|
| 1068 | + $fieldDef['default'] = '0'; |
|
| 1069 | + } |
|
| 1070 | + if (($fieldDef['dbType'] == 'varchar' || $fieldDef['dbType'] == 'enum') && empty($fieldDef['len']) ) { |
|
| 1071 | + $fieldDef['len'] = '255'; |
|
| 1072 | + } |
|
| 1073 | + if ($fieldDef['dbType'] == 'uint') { |
|
| 1074 | + $fieldDef['len'] = '10'; |
|
| 1075 | + } |
|
| 1076 | + if ($fieldDef['dbType'] == 'int' && empty($fieldDef['len']) ) { |
|
| 1077 | + $fieldDef['len'] = '11'; |
|
| 1078 | + } |
|
| 1026 | 1079 | |
| 1027 | 1080 | if($fieldDef['dbType'] == 'decimal') { |
| 1028 | 1081 | if(isset($fieldDef['len'])) { |
@@ -1062,8 +1115,9 @@ discard block |
||
| 1062 | 1115 | } |
| 1063 | 1116 | if (!empty($sql)) { |
| 1064 | 1117 | $sql = "ALTER TABLE $tablename " . join(",", $sql) . ";"; |
| 1065 | - if($execute) |
|
| 1066 | - $this->query($sql); |
|
| 1118 | + if($execute) { |
|
| 1119 | + $this->query($sql); |
|
| 1120 | + } |
|
| 1067 | 1121 | } else { |
| 1068 | 1122 | $sql = ''; |
| 1069 | 1123 | } |
@@ -3,8 +3,7 @@ discard block |
||
| 3 | 3 | * |
| 4 | 4 | * SugarCRM Community Edition is a customer relationship management program developed by |
| 5 | 5 | * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc. |
| 6 | - |
|
| 7 | -* * SuiteCRM is an extension to SugarCRM Community Edition developed by SalesAgility Ltd. |
|
| 6 | + * * SuiteCRM is an extension to SugarCRM Community Edition developed by SalesAgility Ltd. |
|
| 8 | 7 | * Copyright (C) 2011 - 2017 SalesAgility Ltd. |
| 9 | 8 | * |
| 10 | 9 | * This program is free software; you can redistribute it and/or modify it under |
@@ -174,12 +173,12 @@ discard block |
||
| 174 | 173 | */ |
| 175 | 174 | protected $action_view_map = array(); |
| 176 | 175 | |
| 177 | - /** |
|
| 178 | - * This can be set from the application to tell us whether we have authorization to |
|
| 179 | - * process the action. If this is set we will default to the noaccess view. |
|
| 180 | - *@var bool |
|
| 176 | + /** |
|
| 177 | + * This can be set from the application to tell us whether we have authorization to |
|
| 178 | + * process the action. If this is set we will default to the noaccess view. |
|
| 179 | + *@var bool |
|
| 181 | 180 | */ |
| 182 | - public $hasAccess ; |
|
| 181 | + public $hasAccess ; |
|
| 183 | 182 | |
| 184 | 183 | /** |
| 185 | 184 | * Map case sensitive filenames to action. This is used for linux/unix systems |
@@ -191,12 +190,12 @@ discard block |
||
| 191 | 190 | 'listview' => 'ListView' |
| 192 | 191 | ); |
| 193 | 192 | |
| 194 | - /** |
|
| 195 | - * Constructor. This ie meant to load up the module, action, record as well |
|
| 196 | - * as the mapping arrays. |
|
| 197 | - */ |
|
| 198 | - public function __construct() |
|
| 199 | - { |
|
| 193 | + /** |
|
| 194 | + * Constructor. This ie meant to load up the module, action, record as well |
|
| 195 | + * as the mapping arrays. |
|
| 196 | + */ |
|
| 197 | + public function __construct() |
|
| 198 | + { |
|
| 200 | 199 | $this->hasAccess = true;} |
| 201 | 200 | |
| 202 | 201 | /** |
@@ -179,7 +179,7 @@ discard block |
||
| 179 | 179 | * process the action. If this is set we will default to the noaccess view. |
| 180 | 180 | *@var bool |
| 181 | 181 | */ |
| 182 | - public $hasAccess ; |
|
| 182 | + public $hasAccess; |
|
| 183 | 183 | |
| 184 | 184 | /** |
| 185 | 185 | * Map case sensitive filenames to action. This is used for linux/unix systems |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | */ |
| 198 | 198 | public function __construct() |
| 199 | 199 | { |
| 200 | - $this->hasAccess = true;} |
|
| 200 | + $this->hasAccess = true; } |
|
| 201 | 201 | |
| 202 | 202 | /** |
| 203 | 203 | * @deprecated deprecated since version 7.6, PHP4 Style Constructors are deprecated and will be remove in 7.8, please update your code, use __construct instead |
@@ -328,24 +328,24 @@ discard block |
||
| 328 | 328 | */ |
| 329 | 329 | private function loadMapping($var, $merge = false) |
| 330 | 330 | { |
| 331 | - $$var = sugar_cache_retrieve("CONTROLLER_" . $var . "_" . $this->module); |
|
| 331 | + $$var = sugar_cache_retrieve("CONTROLLER_".$var."_".$this->module); |
|
| 332 | 332 | if (!$$var) { |
| 333 | 333 | if ($merge && !empty($this->$var)) { |
| 334 | 334 | $$var = $this->$var; |
| 335 | 335 | } else { |
| 336 | 336 | $$var = array(); |
| 337 | 337 | } |
| 338 | - if (file_exists('include/MVC/Controller/' . $var . '.php')) { |
|
| 339 | - require('include/MVC/Controller/' . $var . '.php'); |
|
| 338 | + if (file_exists('include/MVC/Controller/'.$var.'.php')) { |
|
| 339 | + require('include/MVC/Controller/'.$var.'.php'); |
|
| 340 | 340 | } |
| 341 | - if (file_exists('modules/' . $this->module . '/' . $var . '.php')) { |
|
| 342 | - require('modules/' . $this->module . '/' . $var . '.php'); |
|
| 341 | + if (file_exists('modules/'.$this->module.'/'.$var.'.php')) { |
|
| 342 | + require('modules/'.$this->module.'/'.$var.'.php'); |
|
| 343 | 343 | } |
| 344 | - if (file_exists('custom/modules/' . $this->module . '/' . $var . '.php')) { |
|
| 345 | - require('custom/modules/' . $this->module . '/' . $var . '.php'); |
|
| 344 | + if (file_exists('custom/modules/'.$this->module.'/'.$var.'.php')) { |
|
| 345 | + require('custom/modules/'.$this->module.'/'.$var.'.php'); |
|
| 346 | 346 | } |
| 347 | - if (file_exists('custom/include/MVC/Controller/' . $var . '.php')) { |
|
| 348 | - require('custom/include/MVC/Controller/' . $var . '.php'); |
|
| 347 | + if (file_exists('custom/include/MVC/Controller/'.$var.'.php')) { |
|
| 348 | + require('custom/include/MVC/Controller/'.$var.'.php'); |
|
| 349 | 349 | } |
| 350 | 350 | |
| 351 | 351 | // entry_point_registry -> EntryPointRegistry |
@@ -358,7 +358,7 @@ discard block |
||
| 358 | 358 | require("custom/modules/{$this->module}/Ext/$varname/$var.ext.php"); |
| 359 | 359 | } |
| 360 | 360 | |
| 361 | - sugar_cache_put("CONTROLLER_" . $var . "_" . $this->module, $$var); |
|
| 361 | + sugar_cache_put("CONTROLLER_".$var."_".$this->module, $$var); |
|
| 362 | 362 | } |
| 363 | 363 | $this->$var = $$var; |
| 364 | 364 | } |
@@ -376,7 +376,7 @@ discard block |
||
| 376 | 376 | } elseif (!empty($this->redirect_url)) { |
| 377 | 377 | $this->redirect(); |
| 378 | 378 | } |
| 379 | - } catch (Exception $e) { |
|
| 379 | + }catch (Exception $e) { |
|
| 380 | 380 | $this->handleException($e); |
| 381 | 381 | } |
| 382 | 382 | |
@@ -385,8 +385,8 @@ discard block |
||
| 385 | 385 | |
| 386 | 386 | protected function showException(Exception $e) |
| 387 | 387 | { |
| 388 | - $GLOBALS['log']->fatal('Exception in Controller: ' . $e->getMessage()); |
|
| 389 | - $GLOBALS['log']->fatal("backtrace:\n" . $e->getTraceAsString()); |
|
| 388 | + $GLOBALS['log']->fatal('Exception in Controller: '.$e->getMessage()); |
|
| 389 | + $GLOBALS['log']->fatal("backtrace:\n".$e->getTraceAsString()); |
|
| 390 | 390 | if ($prev = $e->getPrevious()) { |
| 391 | 391 | $GLOBALS['log']->fatal("Previous:\n"); |
| 392 | 392 | $this->showException($prev); |
@@ -399,7 +399,7 @@ discard block |
||
| 399 | 399 | */ |
| 400 | 400 | protected function handleException(Exception $e) |
| 401 | 401 | { |
| 402 | - $GLOBALS['log']->fatal("Exception handling in " . __FILE__ . ':' . __LINE__); |
|
| 402 | + $GLOBALS['log']->fatal("Exception handling in ".__FILE__.':'.__LINE__); |
|
| 403 | 403 | $this->showException($e); |
| 404 | 404 | $logicHook = new LogicHook(); |
| 405 | 405 | |
@@ -519,7 +519,7 @@ discard block |
||
| 519 | 519 | |
| 520 | 520 | $function = $this->getActionMethodName(); |
| 521 | 521 | if ($this->hasFunction($function)) { |
| 522 | - $GLOBALS['log']->debug('Performing action: ' . $function . ' MODULE: ' . $this->module); |
|
| 522 | + $GLOBALS['log']->debug('Performing action: '.$function.' MODULE: '.$this->module); |
|
| 523 | 523 | $this->$function(); |
| 524 | 524 | |
| 525 | 525 | return true; |
@@ -581,7 +581,7 @@ discard block |
||
| 581 | 581 | */ |
| 582 | 582 | protected function getPreActionMethodName() |
| 583 | 583 | { |
| 584 | - return 'pre_' . $this->action; |
|
| 584 | + return 'pre_'.$this->action; |
|
| 585 | 585 | } |
| 586 | 586 | |
| 587 | 587 | /** |
@@ -590,7 +590,7 @@ discard block |
||
| 590 | 590 | */ |
| 591 | 591 | protected function getActionMethodName() |
| 592 | 592 | { |
| 593 | - return 'action_' . strtolower($this->do_action); |
|
| 593 | + return 'action_'.strtolower($this->do_action); |
|
| 594 | 594 | } |
| 595 | 595 | |
| 596 | 596 | /** |
@@ -599,7 +599,7 @@ discard block |
||
| 599 | 599 | */ |
| 600 | 600 | protected function getPostActionMethodName() |
| 601 | 601 | { |
| 602 | - return 'post_' . strtolower($this->action); |
|
| 602 | + return 'post_'.strtolower($this->action); |
|
| 603 | 603 | } |
| 604 | 604 | |
| 605 | 605 | /** |
@@ -655,7 +655,7 @@ discard block |
||
| 655 | 655 | } |
| 656 | 656 | $this->bean->$field = $_POST[$field]; |
| 657 | 657 | } else { |
| 658 | - if (!empty($properties['isMultiSelect']) && !isset($_POST[$field]) && isset($_POST[$field . '_multiselect'])) { |
|
| 658 | + if (!empty($properties['isMultiSelect']) && !isset($_POST[$field]) && isset($_POST[$field.'_multiselect'])) { |
|
| 659 | 659 | $this->bean->$field = ''; |
| 660 | 660 | } |
| 661 | 661 | } |
@@ -699,7 +699,7 @@ discard block |
||
| 699 | 699 | $action = (!empty($this->return_action) ? $this->return_action : 'DetailView'); |
| 700 | 700 | $id = (!empty($this->return_id) ? $this->return_id : $this->bean->id); |
| 701 | 701 | |
| 702 | - $url = "index.php?module=" . $module . "&action=" . $action . "&record=" . $id; |
|
| 702 | + $url = "index.php?module=".$module."&action=".$action."&record=".$id; |
|
| 703 | 703 | $this->set_redirect($url); |
| 704 | 704 | } |
| 705 | 705 | |
@@ -732,22 +732,19 @@ discard block |
||
| 732 | 732 | { |
| 733 | 733 | if (empty($_REQUEST['return_url'])) { |
| 734 | 734 | $return_module = isset($_REQUEST['return_module']) ? |
| 735 | - $_REQUEST['return_module'] : |
|
| 736 | - $GLOBALS['sugar_config']['default_module']; |
|
| 735 | + $_REQUEST['return_module'] : $GLOBALS['sugar_config']['default_module']; |
|
| 737 | 736 | $return_action = isset($_REQUEST['return_action']) ? |
| 738 | - $_REQUEST['return_action'] : |
|
| 739 | - $GLOBALS['sugar_config']['default_action']; |
|
| 737 | + $_REQUEST['return_action'] : $GLOBALS['sugar_config']['default_action']; |
|
| 740 | 738 | $return_id = isset($_REQUEST['return_id']) ? |
| 741 | - $_REQUEST['return_id'] : |
|
| 742 | - ''; |
|
| 743 | - $url = "index.php?module=" . $return_module . "&action=" . $return_action . "&record=" . $return_id; |
|
| 739 | + $_REQUEST['return_id'] : ''; |
|
| 740 | + $url = "index.php?module=".$return_module."&action=".$return_action."&record=".$return_id; |
|
| 744 | 741 | } else { |
| 745 | 742 | $url = $_REQUEST['return_url']; |
| 746 | 743 | } |
| 747 | 744 | |
| 748 | 745 | //eggsurplus Bug 23816: maintain VCR after an edit/save. If it is a duplicate then don't worry about it. The offset is now worthless. |
| 749 | 746 | if (isset($_REQUEST['offset']) && empty($_REQUEST['duplicateSave'])) { |
| 750 | - $url .= "&offset=" . $_REQUEST['offset']; |
|
| 747 | + $url .= "&offset=".$_REQUEST['offset']; |
|
| 751 | 748 | } |
| 752 | 749 | |
| 753 | 750 | $this->set_redirect($url); |
@@ -766,7 +763,7 @@ discard block |
||
| 766 | 763 | sugar_cleanup(true); |
| 767 | 764 | } |
| 768 | 765 | |
| 769 | - set_time_limit(0);//I'm wondering if we will set it never goes timeout here. |
|
| 766 | + set_time_limit(0); //I'm wondering if we will set it never goes timeout here. |
|
| 770 | 767 | // until we have more efficient way of handling MU, we have to disable the limit |
| 771 | 768 | $GLOBALS['db']->setQueryLimit(0); |
| 772 | 769 | require_once("include/MassUpdate.php"); |
@@ -778,7 +775,7 @@ discard block |
||
| 778 | 775 | $mass->generateSearchWhere($_REQUEST['module'], $_REQUEST['current_query_by_page']); |
| 779 | 776 | } |
| 780 | 777 | $mass->handleMassUpdate(); |
| 781 | - $storeQuery = new StoreQuery();//restore the current search. to solve bug 24722 for multi tabs massupdate. |
|
| 778 | + $storeQuery = new StoreQuery(); //restore the current search. to solve bug 24722 for multi tabs massupdate. |
|
| 782 | 779 | $temp_req = array( |
| 783 | 780 | 'current_query_by_page' => $_REQUEST['current_query_by_page'], |
| 784 | 781 | 'return_module' => $_REQUEST['return_module'], |
@@ -794,12 +791,12 @@ discard block |
||
| 794 | 791 | } |
| 795 | 792 | $_REQUEST = array(); |
| 796 | 793 | $_REQUEST = json_decode(html_entity_decode($temp_req['current_query_by_page']), true); |
| 797 | - unset($_REQUEST[$seed->module_dir . '2_' . strtoupper($seed->object_name) . '_offset']);//after massupdate, the page should redirect to no offset page |
|
| 794 | + unset($_REQUEST[$seed->module_dir.'2_'.strtoupper($seed->object_name).'_offset']); //after massupdate, the page should redirect to no offset page |
|
| 798 | 795 | $storeQuery->saveFromRequest($_REQUEST['module']); |
| 799 | 796 | $_REQUEST = array( |
| 800 | 797 | 'return_module' => $temp_req['return_module'], |
| 801 | 798 | 'return_action' => $temp_req['return_action'] |
| 802 | - );//for post_massupdate, to go back to original page. |
|
| 799 | + ); //for post_massupdate, to go back to original page. |
|
| 803 | 800 | } else { |
| 804 | 801 | sugar_die("You must massupdate at least one record"); |
| 805 | 802 | } |
@@ -811,15 +808,13 @@ discard block |
||
| 811 | 808 | protected function post_massupdate() |
| 812 | 809 | { |
| 813 | 810 | $return_module = isset($_REQUEST['return_module']) ? |
| 814 | - $_REQUEST['return_module'] : |
|
| 815 | - $GLOBALS['sugar_config']['default_module']; |
|
| 811 | + $_REQUEST['return_module'] : $GLOBALS['sugar_config']['default_module']; |
|
| 816 | 812 | $return_action = isset($_REQUEST['return_action']) ? |
| 817 | - $_REQUEST['return_action'] : |
|
| 818 | - $GLOBALS['sugar_config']['default_action']; |
|
| 819 | - $url = "index.php?module=" . $return_module . "&action=" . $return_action; |
|
| 813 | + $_REQUEST['return_action'] : $GLOBALS['sugar_config']['default_action']; |
|
| 814 | + $url = "index.php?module=".$return_module."&action=".$return_action; |
|
| 820 | 815 | if ($return_module == 'Emails') {//specificly for My Achieves |
| 821 | 816 | if (!empty($this->req_for_email['type']) && !empty($this->req_for_email['ie_assigned_user_id'])) { |
| 822 | - $url = $url . "&type=" . $this->req_for_email['type'] . "&assigned_user_id=" . $this->req_for_email['ie_assigned_user_id']; |
|
| 817 | + $url = $url."&type=".$this->req_for_email['type']."&assigned_user_id=".$this->req_for_email['ie_assigned_user_id']; |
|
| 823 | 818 | } |
| 824 | 819 | } |
| 825 | 820 | $this->set_redirect($url); |
@@ -893,8 +888,8 @@ discard block |
||
| 893 | 888 | } else { // display options |
| 894 | 889 | $json = getJSONobj(); |
| 895 | 890 | |
| 896 | - return 'result = ' . $json->encode((array( |
|
| 897 | - 'header' => $dashlet->title . ' : ' . $mod_strings['LBL_OPTIONS'], |
|
| 891 | + return 'result = '.$json->encode((array( |
|
| 892 | + 'header' => $dashlet->title.' : '.$mod_strings['LBL_OPTIONS'], |
|
| 898 | 893 | 'body' => $dashlet->displayOptions() |
| 899 | 894 | ))); |
| 900 | 895 | |
@@ -1054,15 +1049,15 @@ discard block |
||
| 1054 | 1049 | $action = 'list'; |
| 1055 | 1050 | } |
| 1056 | 1051 | |
| 1057 | - if ((file_exists('modules/' . $this->module . '/' . $file . '.php') |
|
| 1058 | - && !file_exists('modules/' . $this->module . '/views/view.' . $action . '.php')) |
|
| 1059 | - || (file_exists('custom/modules/' . $this->module . '/' . $file . '.php') |
|
| 1060 | - && !file_exists('custom/modules/' . $this->module . '/views/view.' . $action . '.php')) |
|
| 1052 | + if ((file_exists('modules/'.$this->module.'/'.$file.'.php') |
|
| 1053 | + && !file_exists('modules/'.$this->module.'/views/view.'.$action.'.php')) |
|
| 1054 | + || (file_exists('custom/modules/'.$this->module.'/'.$file.'.php') |
|
| 1055 | + && !file_exists('custom/modules/'.$this->module.'/views/view.'.$action.'.php')) |
|
| 1061 | 1056 | ) { |
| 1062 | 1057 | // A 'classic' module, using the old pre-MVC display files |
| 1063 | 1058 | // We should now discard the bean we just obtained for tracking as the pre-MVC module will instantiate its own |
| 1064 | 1059 | unset($GLOBALS['FOCUS']); |
| 1065 | - $GLOBALS['log']->debug('Module:' . $this->module . ' using file: ' . $file); |
|
| 1060 | + $GLOBALS['log']->debug('Module:'.$this->module.' using file: '.$file); |
|
| 1066 | 1061 | $this->action_default(); |
| 1067 | 1062 | $this->_processed = true; |
| 1068 | 1063 | } |
@@ -1077,11 +1072,11 @@ discard block |
||
| 1077 | 1072 | { |
| 1078 | 1073 | if (!empty($this->action_file_map[strtolower($this->do_action)])) { |
| 1079 | 1074 | $this->view = ''; |
| 1080 | - $GLOBALS['log']->debug('Using Action File Map:' . $this->action_file_map[strtolower($this->do_action)]); |
|
| 1075 | + $GLOBALS['log']->debug('Using Action File Map:'.$this->action_file_map[strtolower($this->do_action)]); |
|
| 1081 | 1076 | require_once($this->action_file_map[strtolower($this->do_action)]); |
| 1082 | 1077 | $this->_processed = true; |
| 1083 | 1078 | } elseif (!empty($this->action_view_map[strtolower($this->do_action)])) { |
| 1084 | - $GLOBALS['log']->debug('Using Action View Map:' . $this->action_view_map[strtolower($this->do_action)]); |
|
| 1079 | + $GLOBALS['log']->debug('Using Action View Map:'.$this->action_view_map[strtolower($this->do_action)]); |
|
| 1085 | 1080 | $this->view = $this->action_view_map[strtolower($this->do_action)]; |
| 1086 | 1081 | $this->_processed = true; |
| 1087 | 1082 | } else { |
@@ -62,42 +62,42 @@ |
||
| 62 | 62 | |
| 63 | 63 | require_once('include/formbase.php'); |
| 64 | 64 | |
| 65 | - global $beanFiles,$beanList; |
|
| 66 | - $bean_name = $beanList[$_REQUEST['module']]; |
|
| 67 | - require_once($beanFiles[$bean_name]); |
|
| 68 | - $focus = new $bean_name(); |
|
| 69 | - if ( empty($_REQUEST['linked_id']) || empty($_REQUEST['linked_field']) || empty($_REQUEST['record'])){ |
|
| 70 | - |
|
| 71 | - die("need linked_field, linked_id and record fields"); |
|
| 72 | - } |
|
| 73 | - $linked_field = $_REQUEST['linked_field']; |
|
| 74 | - $record = $_REQUEST['record']; |
|
| 75 | - $linked_id = $_REQUEST['linked_id']; |
|
| 76 | - if ($linked_field === 'aclroles') { |
|
| 65 | + global $beanFiles,$beanList; |
|
| 66 | + $bean_name = $beanList[$_REQUEST['module']]; |
|
| 67 | + require_once($beanFiles[$bean_name]); |
|
| 68 | + $focus = new $bean_name(); |
|
| 69 | + if ( empty($_REQUEST['linked_id']) || empty($_REQUEST['linked_field']) || empty($_REQUEST['record'])){ |
|
| 70 | + |
|
| 71 | + die("need linked_field, linked_id and record fields"); |
|
| 72 | + } |
|
| 73 | + $linked_field = $_REQUEST['linked_field']; |
|
| 74 | + $record = $_REQUEST['record']; |
|
| 75 | + $linked_id = $_REQUEST['linked_id']; |
|
| 76 | + if ($linked_field === 'aclroles') { |
|
| 77 | 77 | if (!ACLController::checkAccess($bean_name, 'edit', true)) { |
| 78 | 78 | ACLController::displayNoAccess(); |
| 79 | 79 | sugar_cleanup(true); |
| 80 | 80 | } |
| 81 | 81 | }if($linked_field === 'aclroles') { |
| 82 | 82 | if (!ACLController::checkAccess($bean_name , 'edit', true)) { |
| 83 | - ACLController::displayNoAccess(); |
|
| 83 | + ACLController::displayNoAccess(); |
|
| 84 | 84 | sugar_cleanup(true); |
| 85 | 85 | } |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | if ($bean_name === 'Team'){ |
| 89 | - $focus->retrieve($record); |
|
| 90 | - $focus->remove_user_from_team($linked_id); |
|
| 91 | - } |
|
| 92 | - else{ |
|
| 93 | - |
|
| 94 | - // cut it off: |
|
| 95 | - $focus->load_relationship($linked_field); |
|
| 96 | - if($focus->$linked_field->_relationship->relationship_name === 'quotes_contacts_shipto'){ |
|
| 97 | - unset($focus->$linked_field->_relationship->relationship_role_column);} |
|
| 98 | - $focus->$linked_field->delete($record,$linked_id); |
|
| 99 | - } |
|
| 100 | - if ($bean_name === 'Campaign' and $linked_field==='prospectlists' ) { |
|
| 89 | + $focus->retrieve($record); |
|
| 90 | + $focus->remove_user_from_team($linked_id); |
|
| 91 | + } |
|
| 92 | + else{ |
|
| 93 | + |
|
| 94 | + // cut it off: |
|
| 95 | + $focus->load_relationship($linked_field); |
|
| 96 | + if($focus->$linked_field->_relationship->relationship_name === 'quotes_contacts_shipto'){ |
|
| 97 | + unset($focus->$linked_field->_relationship->relationship_role_column);} |
|
| 98 | + $focus->$linked_field->delete($record,$linked_id); |
|
| 99 | + } |
|
| 100 | + if ($bean_name === 'Campaign' and $linked_field==='prospectlists' ) { |
|
| 101 | 101 | |
| 102 | 102 | $query = "SELECT email_marketing_prospect_lists.id from email_marketing_prospect_lists "; |
| 103 | 103 | $query .= " left join email_marketing on email_marketing.id=email_marketing_prospect_lists.email_marketing_id"; |
@@ -62,11 +62,11 @@ discard block |
||
| 62 | 62 | |
| 63 | 63 | require_once('include/formbase.php'); |
| 64 | 64 | |
| 65 | - global $beanFiles,$beanList; |
|
| 65 | + global $beanFiles, $beanList; |
|
| 66 | 66 | $bean_name = $beanList[$_REQUEST['module']]; |
| 67 | 67 | require_once($beanFiles[$bean_name]); |
| 68 | 68 | $focus = new $bean_name(); |
| 69 | - if ( empty($_REQUEST['linked_id']) || empty($_REQUEST['linked_field']) || empty($_REQUEST['record'])){ |
|
| 69 | + if (empty($_REQUEST['linked_id']) || empty($_REQUEST['linked_field']) || empty($_REQUEST['record'])) { |
|
| 70 | 70 | |
| 71 | 71 | die("need linked_field, linked_id and record fields"); |
| 72 | 72 | } |
@@ -78,26 +78,26 @@ discard block |
||
| 78 | 78 | ACLController::displayNoAccess(); |
| 79 | 79 | sugar_cleanup(true); |
| 80 | 80 | } |
| 81 | -}if($linked_field === 'aclroles') { |
|
| 82 | - if (!ACLController::checkAccess($bean_name , 'edit', true)) { |
|
| 81 | +}if ($linked_field === 'aclroles') { |
|
| 82 | + if (!ACLController::checkAccess($bean_name, 'edit', true)) { |
|
| 83 | 83 | ACLController::displayNoAccess(); |
| 84 | 84 | sugar_cleanup(true); |
| 85 | 85 | } |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | -if ($bean_name === 'Team'){ |
|
| 88 | +if ($bean_name === 'Team') { |
|
| 89 | 89 | $focus->retrieve($record); |
| 90 | 90 | $focus->remove_user_from_team($linked_id); |
| 91 | 91 | } |
| 92 | - else{ |
|
| 92 | + else { |
|
| 93 | 93 | |
| 94 | 94 | // cut it off: |
| 95 | 95 | $focus->load_relationship($linked_field); |
| 96 | - if($focus->$linked_field->_relationship->relationship_name === 'quotes_contacts_shipto'){ |
|
| 97 | - unset($focus->$linked_field->_relationship->relationship_role_column);} |
|
| 98 | - $focus->$linked_field->delete($record,$linked_id); |
|
| 96 | + if ($focus->$linked_field->_relationship->relationship_name === 'quotes_contacts_shipto') { |
|
| 97 | + unset($focus->$linked_field->_relationship->relationship_role_column); } |
|
| 98 | + $focus->$linked_field->delete($record, $linked_id); |
|
| 99 | 99 | } |
| 100 | - if ($bean_name === 'Campaign' and $linked_field==='prospectlists' ) { |
|
| 100 | + if ($bean_name === 'Campaign' and $linked_field === 'prospectlists') { |
|
| 101 | 101 | |
| 102 | 102 | $query = "SELECT email_marketing_prospect_lists.id from email_marketing_prospect_lists "; |
| 103 | 103 | $query .= " left join email_marketing on email_marketing.id=email_marketing_prospect_lists.email_marketing_id"; |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | |
| 107 | 107 | $result = $focus->db->query($query); |
| 108 | 108 | while (($row = $focus->db->fetchByAssoc($result)) != null) { |
| 109 | - $del_query = " update email_marketing_prospect_lists set email_marketing_prospect_lists.deleted=1, email_marketing_prospect_lists.date_modified=" . $focus->db->convert("'" . TimeDate::getInstance()->nowDb() . "'", |
|
| 109 | + $del_query = " update email_marketing_prospect_lists set email_marketing_prospect_lists.deleted=1, email_marketing_prospect_lists.date_modified=".$focus->db->convert("'".TimeDate::getInstance()->nowDb()."'", |
|
| 110 | 110 | 'datetime'); |
| 111 | 111 | $del_query .= " WHERE email_marketing_prospect_lists.id='{$row['id']}'"; |
| 112 | 112 | $focus->db->query($del_query); |
@@ -88,8 +88,7 @@ |
||
| 88 | 88 | if ($bean_name === 'Team'){ |
| 89 | 89 | $focus->retrieve($record); |
| 90 | 90 | $focus->remove_user_from_team($linked_id); |
| 91 | - } |
|
| 92 | - else{ |
|
| 91 | + } else{ |
|
| 93 | 92 | |
| 94 | 93 | // cut it off: |
| 95 | 94 | $focus->load_relationship($linked_field); |
@@ -60,50 +60,50 @@ |
||
| 60 | 60 | $parent_record_id = $_REQUEST['record']; |
| 61 | 61 | $parent_module = $_REQUEST['module']; |
| 62 | 62 | |
| 63 | - $action = 'DeleteRelationship'; |
|
| 64 | - $record = $layout_def['fields']['ID']; |
|
| 65 | - $current_module=$layout_def['module']; |
|
| 66 | - //in document revisions subpanel ,users are now allowed to |
|
| 67 | - //delete the latest revsion of a document. this will be tested here |
|
| 68 | - //and if the condition is met delete button will be removed. |
|
| 69 | - $hideremove=false; |
|
| 70 | - if ($current_module==='DocumentRevisions') { |
|
| 71 | - if ($layout_def['fields']['ID']===$layout_def['fields']['LATEST_REVISION_ID']) { |
|
| 72 | - $hideremove=true; |
|
| 73 | - } |
|
| 74 | - }elseif ($_REQUEST['module'] === 'Teams' && $current_module === 'Users') { |
|
| 75 | - // Implicit Team-memberships are not "removeable" |
|
| 76 | - |
|
| 77 | - if($layout_def['fields']['UPLINE'] !== translate('LBL_TEAM_UPLINE_EXPLICIT', 'Users')) { |
|
| 78 | - $hideremove = true; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - //We also cannot remove the user whose private team is set to the parent_record_id value |
|
| 82 | - $user = new User(); |
|
| 83 | - $user->retrieve($layout_def['fields']['ID']); |
|
| 84 | - if($parent_record_id === $user->getPrivateTeamID()){ |
|
| 85 | - |
|
| 86 | - $hideremove = true; |
|
| 87 | - }} elseif ($current_module === 'ACLRoles' && (!ACLController::checkAccess($current_module, 'edit', true))) { |
|
| 63 | + $action = 'DeleteRelationship'; |
|
| 64 | + $record = $layout_def['fields']['ID']; |
|
| 65 | + $current_module=$layout_def['module']; |
|
| 66 | + //in document revisions subpanel ,users are now allowed to |
|
| 67 | + //delete the latest revsion of a document. this will be tested here |
|
| 68 | + //and if the condition is met delete button will be removed. |
|
| 69 | + $hideremove=false; |
|
| 70 | + if ($current_module==='DocumentRevisions') { |
|
| 71 | + if ($layout_def['fields']['ID']===$layout_def['fields']['LATEST_REVISION_ID']) { |
|
| 72 | + $hideremove=true; |
|
| 73 | + } |
|
| 74 | + }elseif ($_REQUEST['module'] === 'Teams' && $current_module === 'Users') { |
|
| 75 | + // Implicit Team-memberships are not "removeable" |
|
| 76 | + |
|
| 77 | + if($layout_def['fields']['UPLINE'] !== translate('LBL_TEAM_UPLINE_EXPLICIT', 'Users')) { |
|
| 78 | + $hideremove = true; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + //We also cannot remove the user whose private team is set to the parent_record_id value |
|
| 82 | + $user = new User(); |
|
| 83 | + $user->retrieve($layout_def['fields']['ID']); |
|
| 84 | + if($parent_record_id === $user->getPrivateTeamID()){ |
|
| 85 | + |
|
| 86 | + $hideremove = true; |
|
| 87 | + }} elseif ($current_module === 'ACLRoles' && (!ACLController::checkAccess($current_module, 'edit', true))) { |
|
| 88 | 88 | $hideremove = true; |
| 89 | - }elseif ($current_module === 'ACLRoles' && (!ACLController::checkAccess($current_module, 'edit', true))) { |
|
| 89 | + }elseif ($current_module === 'ACLRoles' && (!ACLController::checkAccess($current_module, 'edit', true))) { |
|
| 90 | 90 | $hideremove = true; |
| 91 | - } |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - $return_module = $_REQUEST['module']; |
|
| 94 | - $return_action = 'SubPanelViewer'; |
|
| 95 | - $subpanel = $layout_def['subpanel_id']; |
|
| 96 | - $return_id = $_REQUEST['record']; |
|
| 97 | - if (isset($layout_def['linked_field_set']) && !empty($layout_def['linked_field_set'])) { |
|
| 98 | - $linked_field= $layout_def['linked_field_set'] ; |
|
| 99 | - } else { |
|
| 100 | - $linked_field = $layout_def['linked_field']; |
|
| 101 | - } |
|
| 102 | - $refresh_page = 0; |
|
| 103 | - if(!empty($layout_def['refresh_page'])){ |
|
| 104 | - $refresh_page = 1; |
|
| 105 | - } |
|
| 106 | - $return_url = "index.php?module=$return_module&action=$return_action&subpanel=$subpanel&record=$return_id&sugar_body_only=1&inline=1"; |
|
| 93 | + $return_module = $_REQUEST['module']; |
|
| 94 | + $return_action = 'SubPanelViewer'; |
|
| 95 | + $subpanel = $layout_def['subpanel_id']; |
|
| 96 | + $return_id = $_REQUEST['record']; |
|
| 97 | + if (isset($layout_def['linked_field_set']) && !empty($layout_def['linked_field_set'])) { |
|
| 98 | + $linked_field= $layout_def['linked_field_set'] ; |
|
| 99 | + } else { |
|
| 100 | + $linked_field = $layout_def['linked_field']; |
|
| 101 | + } |
|
| 102 | + $refresh_page = 0; |
|
| 103 | + if(!empty($layout_def['refresh_page'])){ |
|
| 104 | + $refresh_page = 1; |
|
| 105 | + } |
|
| 106 | + $return_url = "index.php?module=$return_module&action=$return_action&subpanel=$subpanel&record=$return_id&sugar_body_only=1&inline=1"; |
|
| 107 | 107 | |
| 108 | 108 | $icon_remove_text = $app_strings['LBL_ID_FF_REMOVE']; |
| 109 | 109 | |
@@ -55,33 +55,33 @@ discard block |
||
| 55 | 55 | global $app_strings; |
| 56 | 56 | global $subpanel_item_count; |
| 57 | 57 | |
| 58 | - $unique_id = $layout_def['subpanel_id'] . "_remove_" . $subpanel_item_count; //bug 51512 |
|
| 58 | + $unique_id = $layout_def['subpanel_id']."_remove_".$subpanel_item_count; //bug 51512 |
|
| 59 | 59 | |
| 60 | 60 | $parent_record_id = $_REQUEST['record']; |
| 61 | 61 | $parent_module = $_REQUEST['module']; |
| 62 | 62 | |
| 63 | 63 | $action = 'DeleteRelationship'; |
| 64 | 64 | $record = $layout_def['fields']['ID']; |
| 65 | - $current_module=$layout_def['module']; |
|
| 65 | + $current_module = $layout_def['module']; |
|
| 66 | 66 | //in document revisions subpanel ,users are now allowed to |
| 67 | 67 | //delete the latest revsion of a document. this will be tested here |
| 68 | 68 | //and if the condition is met delete button will be removed. |
| 69 | - $hideremove=false; |
|
| 70 | - if ($current_module==='DocumentRevisions') { |
|
| 71 | - if ($layout_def['fields']['ID']===$layout_def['fields']['LATEST_REVISION_ID']) { |
|
| 72 | - $hideremove=true; |
|
| 69 | + $hideremove = false; |
|
| 70 | + if ($current_module === 'DocumentRevisions') { |
|
| 71 | + if ($layout_def['fields']['ID'] === $layout_def['fields']['LATEST_REVISION_ID']) { |
|
| 72 | + $hideremove = true; |
|
| 73 | 73 | } |
| 74 | 74 | }elseif ($_REQUEST['module'] === 'Teams' && $current_module === 'Users') { |
| 75 | 75 | // Implicit Team-memberships are not "removeable" |
| 76 | 76 | |
| 77 | - if($layout_def['fields']['UPLINE'] !== translate('LBL_TEAM_UPLINE_EXPLICIT', 'Users')) { |
|
| 77 | + if ($layout_def['fields']['UPLINE'] !== translate('LBL_TEAM_UPLINE_EXPLICIT', 'Users')) { |
|
| 78 | 78 | $hideremove = true; |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | //We also cannot remove the user whose private team is set to the parent_record_id value |
| 82 | 82 | $user = new User(); |
| 83 | 83 | $user->retrieve($layout_def['fields']['ID']); |
| 84 | - if($parent_record_id === $user->getPrivateTeamID()){ |
|
| 84 | + if ($parent_record_id === $user->getPrivateTeamID()) { |
|
| 85 | 85 | |
| 86 | 86 | $hideremove = true; |
| 87 | 87 | }} elseif ($current_module === 'ACLRoles' && (!ACLController::checkAccess($current_module, 'edit', true))) { |
@@ -95,12 +95,12 @@ discard block |
||
| 95 | 95 | $subpanel = $layout_def['subpanel_id']; |
| 96 | 96 | $return_id = $_REQUEST['record']; |
| 97 | 97 | if (isset($layout_def['linked_field_set']) && !empty($layout_def['linked_field_set'])) { |
| 98 | - $linked_field= $layout_def['linked_field_set'] ; |
|
| 98 | + $linked_field = $layout_def['linked_field_set']; |
|
| 99 | 99 | } else { |
| 100 | 100 | $linked_field = $layout_def['linked_field']; |
| 101 | 101 | } |
| 102 | 102 | $refresh_page = 0; |
| 103 | - if(!empty($layout_def['refresh_page'])){ |
|
| 103 | + if (!empty($layout_def['refresh_page'])) { |
|
| 104 | 104 | $refresh_page = 1; |
| 105 | 105 | } |
| 106 | 106 | $return_url = "index.php?module=$return_module&action=$return_action&subpanel=$subpanel&record=$return_id&sugar_body_only=1&inline=1"; |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | if ($layout_def['fields']['ID']===$layout_def['fields']['LATEST_REVISION_ID']) { |
| 72 | 72 | $hideremove=true; |
| 73 | 73 | } |
| 74 | - }elseif ($_REQUEST['module'] === 'Teams' && $current_module === 'Users') { |
|
| 74 | + } elseif ($_REQUEST['module'] === 'Teams' && $current_module === 'Users') { |
|
| 75 | 75 | // Implicit Team-memberships are not "removeable" |
| 76 | 76 | |
| 77 | 77 | if($layout_def['fields']['UPLINE'] !== translate('LBL_TEAM_UPLINE_EXPLICIT', 'Users')) { |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | $hideremove = true; |
| 87 | 87 | }} elseif ($current_module === 'ACLRoles' && (!ACLController::checkAccess($current_module, 'edit', true))) { |
| 88 | 88 | $hideremove = true; |
| 89 | - }elseif ($current_module === 'ACLRoles' && (!ACLController::checkAccess($current_module, 'edit', true))) { |
|
| 89 | + } elseif ($current_module === 'ACLRoles' && (!ACLController::checkAccess($current_module, 'edit', true))) { |
|
| 90 | 90 | $hideremove = true; |
| 91 | 91 | } |
| 92 | 92 | |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | */ |
| 115 | 115 | public static function clearCache($module, $view = '') |
| 116 | 116 | { |
| 117 | - $cacheDir = create_cache_directory('modules/' . $module . '/'); |
|
| 117 | + $cacheDir = create_cache_directory('modules/'.$module.'/'); |
|
| 118 | 118 | $d = dir($cacheDir); |
| 119 | 119 | while ($e = $d->read()) { |
| 120 | 120 | if (!empty($view) && $e !== $view) { |
@@ -122,8 +122,8 @@ discard block |
||
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | $end = strlen($e) - 4; |
| 125 | - if (is_file($cacheDir . $e) && $end > 1 && substr($e, $end) === '.tpl') { |
|
| 126 | - unlink($cacheDir . $e); |
|
| 125 | + if (is_file($cacheDir.$e) && $end > 1 && substr($e, $end) === '.tpl') { |
|
| 126 | + unlink($cacheDir.$e); |
|
| 127 | 127 | } |
| 128 | 128 | } |
| 129 | 129 | |
@@ -134,10 +134,10 @@ discard block |
||
| 134 | 134 | * The tpl files for each theme should be cleared for consistency. |
| 135 | 135 | */ |
| 136 | 136 | $cacheDir = rtrim($GLOBALS['sugar_config']['cache_dir'], '/\\'); |
| 137 | - $themesDir = array_filter(glob($cacheDir . '/themes/*'), 'is_dir'); |
|
| 137 | + $themesDir = array_filter(glob($cacheDir.'/themes/*'), 'is_dir'); |
|
| 138 | 138 | |
| 139 | 139 | foreach ($themesDir as $theme) { |
| 140 | - $tplDir = $theme . '/modules/' . $module . '/'; |
|
| 140 | + $tplDir = $theme.'/modules/'.$module.'/'; |
|
| 141 | 141 | if (!file_exists($tplDir)) { |
| 142 | 142 | continue; |
| 143 | 143 | } |
@@ -148,8 +148,8 @@ discard block |
||
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | $end = strlen($e) - 4; |
| 151 | - if ($end > 1 && is_file($tplDir . $e) && substr($e, $end) === '.tpl') { |
|
| 152 | - unlink($tplDir . $e); |
|
| 151 | + if ($end > 1 && is_file($tplDir.$e) && substr($e, $end) === '.tpl') { |
|
| 152 | + unlink($tplDir.$e); |
|
| 153 | 153 | } |
| 154 | 154 | } |
| 155 | 155 | } |
@@ -171,8 +171,8 @@ discard block |
||
| 171 | 171 | global $theme; |
| 172 | 172 | |
| 173 | 173 | $this->loadSmarty(); |
| 174 | - $cacheDir = create_cache_directory($this->themeDir . $theme . '/' . $this->templateDir . $module . '/'); |
|
| 175 | - $file = $cacheDir . $view . '.tpl'; |
|
| 174 | + $cacheDir = create_cache_directory($this->themeDir.$theme.'/'.$this->templateDir.$module.'/'); |
|
| 175 | + $file = $cacheDir.$view.'.tpl'; |
|
| 176 | 176 | $this->ss->left_delimiter = '{{'; |
| 177 | 177 | $this->ss->right_delimiter = '}}'; |
| 178 | 178 | $this->ss->assign('module', $module); |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | |
| 258 | 258 | $validatedFields = array(); |
| 259 | 259 | $javascript->addToValidateBinaryDependency('assigned_user_name', 'alpha', |
| 260 | - $javascript->buildStringToTranslateInSmarty('ERR_SQS_NO_MATCH_FIELD') . ': ' . $javascript->buildStringToTranslateInSmarty('LBL_ASSIGNED_TO'), |
|
| 260 | + $javascript->buildStringToTranslateInSmarty('ERR_SQS_NO_MATCH_FIELD').': '.$javascript->buildStringToTranslateInSmarty('LBL_ASSIGNED_TO'), |
|
| 261 | 261 | 'false', '', 'assigned_user_id'); |
| 262 | 262 | $validatedFields[] = 'assigned_user_name'; |
| 263 | 263 | //Add remaining validation dependency for related fields |
@@ -284,7 +284,7 @@ discard block |
||
| 284 | 284 | $vname = "undefined"; |
| 285 | 285 | } |
| 286 | 286 | $javascript->addToValidateBinaryDependency($name, 'alpha', |
| 287 | - $javascript->buildStringToTranslateInSmarty('ERR_SQS_NO_MATCH_FIELD') . ': ' . $javascript->buildStringToTranslateInSmarty($vname), |
|
| 287 | + $javascript->buildStringToTranslateInSmarty('ERR_SQS_NO_MATCH_FIELD').': '.$javascript->buildStringToTranslateInSmarty($vname), |
|
| 288 | 288 | (!empty($def['required']) ? 'true' : 'false'), '', $def['id_name']); |
| 289 | 289 | $validatedFields[] = $name; |
| 290 | 290 | } |
@@ -340,7 +340,7 @@ discard block |
||
| 340 | 340 | } |
| 341 | 341 | $view = $checkFormName ? $formName : $view; |
| 342 | 342 | |
| 343 | - return file_exists($this->cacheDir . $this->themeDir . $theme . '/' . $this->templateDir . $module . '/' . $view . '.tpl'); |
|
| 343 | + return file_exists($this->cacheDir.$this->themeDir.$theme.'/'.$this->templateDir.$module.'/'.$view.'.tpl'); |
|
| 344 | 344 | } |
| 345 | 345 | |
| 346 | 346 | /** |
@@ -360,14 +360,14 @@ discard block |
||
| 360 | 360 | if (!$this->checkTemplate($module, $view)) { |
| 361 | 361 | $this->buildTemplate($module, $view, $tpl, $ajaxSave, $metaDataDefs); |
| 362 | 362 | } |
| 363 | - $file = $this->cacheDir . $this->themeDir . $theme . '/' . $this->templateDir . $module . '/' . $view . '.tpl'; |
|
| 363 | + $file = $this->cacheDir.$this->themeDir.$theme.'/'.$this->templateDir.$module.'/'.$view.'.tpl'; |
|
| 364 | 364 | if (file_exists($file)) { |
| 365 | 365 | return $this->ss->fetch($file); |
| 366 | 366 | } else { |
| 367 | 367 | global $app_strings; |
| 368 | - $GLOBALS['log']->fatal($app_strings['ERR_NO_SUCH_FILE'] . ": $file"); |
|
| 368 | + $GLOBALS['log']->fatal($app_strings['ERR_NO_SUCH_FILE'].": $file"); |
|
| 369 | 369 | |
| 370 | - return $app_strings['ERR_NO_SUCH_FILE'] . ": $file"; |
|
| 370 | + return $app_strings['ERR_NO_SUCH_FILE'].": $file"; |
|
| 371 | 371 | } |
| 372 | 372 | } |
| 373 | 373 | |
@@ -381,15 +381,15 @@ discard block |
||
| 381 | 381 | public function deleteTemplate($module, $view) |
| 382 | 382 | { |
| 383 | 383 | global $theme; |
| 384 | - if (is_file($this->cacheDir . $this->themeDir . $theme . '/' . $this->templateDir . $module . '/' . $view . '.tpl')) { |
|
| 384 | + if (is_file($this->cacheDir.$this->themeDir.$theme.'/'.$this->templateDir.$module.'/'.$view.'.tpl')) { |
|
| 385 | 385 | // Bug #54634 : RTC 18144 : Cannot add more than 1 user to role but popup is multi-selectable |
| 386 | 386 | if (!isset($this->ss)) { |
| 387 | 387 | $this->loadSmarty(); |
| 388 | 388 | } |
| 389 | - $cache_file_name = $this->ss->_get_compile_path($this->cacheDir . $this->themeDir . $theme . '/' . $this->templateDir . $module . '/' . $view . '.tpl'); |
|
| 389 | + $cache_file_name = $this->ss->_get_compile_path($this->cacheDir.$this->themeDir.$theme.'/'.$this->templateDir.$module.'/'.$view.'.tpl'); |
|
| 390 | 390 | SugarCache::cleanFile($cache_file_name); |
| 391 | 391 | |
| 392 | - return unlink($this->cacheDir . $this->themeDir . $theme . '/' . $this->templateDir . $module . '/' . $view . '.tpl'); |
|
| 392 | + return unlink($this->cacheDir.$this->themeDir.$theme.'/'.$this->templateDir.$module.'/'.$view.'.tpl'); |
|
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | return false; |
@@ -430,7 +430,7 @@ discard block |
||
| 430 | 430 | //Loop through the Meta-Data fields to see which ones need quick search support |
| 431 | 431 | foreach ($defs as $f) { |
| 432 | 432 | $field = $f; |
| 433 | - $name = $qsd->form_name . '_' . $field['name']; |
|
| 433 | + $name = $qsd->form_name.'_'.$field['name']; |
|
| 434 | 434 | |
| 435 | 435 | if (($field['type'] === 'relate' && |
| 436 | 436 | isset($field['module']) && |
@@ -441,20 +441,20 @@ discard block |
||
| 441 | 441 | if (preg_match('/^(Campaigns|Teams|Users|Contacts|Accounts)$/si', $field['module'], $matches)) { |
| 442 | 442 | |
| 443 | 443 | if ($matches[0] === 'Campaigns') { |
| 444 | - $sqs_objects[$name . '_' . $parsedView] = $qsd->loadQSObject('Campaigns', 'Campaign', |
|
| 444 | + $sqs_objects[$name.'_'.$parsedView] = $qsd->loadQSObject('Campaigns', 'Campaign', |
|
| 445 | 445 | $field['name'], $field['id_name'], $field['id_name']); |
| 446 | 446 | } else { |
| 447 | 447 | if ($matches[0] === 'Users') { |
| 448 | 448 | |
| 449 | 449 | if (!empty($f['name']) && !empty($f['id_name'])) { |
| 450 | - $sqs_objects[$name . '_' . $parsedView] = $qsd->getQSUser($f['name'], |
|
| 450 | + $sqs_objects[$name.'_'.$parsedView] = $qsd->getQSUser($f['name'], |
|
| 451 | 451 | $f['id_name']); |
| 452 | 452 | } else { |
| 453 | - $sqs_objects[$name . '_' . $parsedView] = $qsd->getQSUser(); |
|
| 453 | + $sqs_objects[$name.'_'.$parsedView] = $qsd->getQSUser(); |
|
| 454 | 454 | } |
| 455 | 455 | } else { |
| 456 | 456 | if ($matches[0] === 'Campaigns') { |
| 457 | - $sqs_objects[$name . '_' . $parsedView] = $qsd->loadQSObject('Campaigns', |
|
| 457 | + $sqs_objects[$name.'_'.$parsedView] = $qsd->loadQSObject('Campaigns', |
|
| 458 | 458 | 'Campaign', $field['name'], $field['id_name'], $field['id_name']); |
| 459 | 459 | } else { |
| 460 | 460 | if ($matches[0] === 'Accounts') { |
@@ -469,11 +469,11 @@ discard block |
||
| 469 | 469 | $billingKey = isset($f['displayParams']['billingKey']) ? $f['displayParams']['billingKey'] : null; |
| 470 | 470 | $shippingKey = isset($f['displayParams']['shippingKey']) ? $f['displayParams']['shippingKey'] : null; |
| 471 | 471 | $additionalFields = isset($f['displayParams']['additionalFields']) ? $f['displayParams']['additionalFields'] : null; |
| 472 | - $sqs_objects[$name . '_' . $parsedView] = $qsd->getQSAccount($nameKey, $idKey, |
|
| 472 | + $sqs_objects[$name.'_'.$parsedView] = $qsd->getQSAccount($nameKey, $idKey, |
|
| 473 | 473 | $billingKey, $shippingKey, $additionalFields); |
| 474 | 474 | } else { |
| 475 | 475 | if ($matches[0] === 'Contacts') { |
| 476 | - $sqs_objects[$name . '_' . $parsedView] = $qsd->getQSContact($field['name'], |
|
| 476 | + $sqs_objects[$name.'_'.$parsedView] = $qsd->getQSContact($field['name'], |
|
| 477 | 477 | $field['id_name']); |
| 478 | 478 | } |
| 479 | 479 | } |
@@ -481,28 +481,28 @@ discard block |
||
| 481 | 481 | } |
| 482 | 482 | } |
| 483 | 483 | } else { |
| 484 | - $sqs_objects[$name . '_' . $parsedView] = $qsd->getQSParent($field['module']); |
|
| 484 | + $sqs_objects[$name.'_'.$parsedView] = $qsd->getQSParent($field['module']); |
|
| 485 | 485 | if (!isset($field['field_list']) && !isset($field['populate_list'])) { |
| 486 | - $sqs_objects[$name . '_' . $parsedView]['populate_list'] = array( |
|
| 486 | + $sqs_objects[$name.'_'.$parsedView]['populate_list'] = array( |
|
| 487 | 487 | $field['name'], |
| 488 | 488 | $field['id_name'] |
| 489 | 489 | ); |
| 490 | - $sqs_objects[$name . '_' . $parsedView]['field_list'] = array('name', 'id'); |
|
| 490 | + $sqs_objects[$name.'_'.$parsedView]['field_list'] = array('name', 'id'); |
|
| 491 | 491 | } else { |
| 492 | - $sqs_objects[$name . '_' . $parsedView]['populate_list'] = $field['field_list']; |
|
| 493 | - $sqs_objects[$name . '_' . $parsedView]['field_list'] = $field['populate_list']; |
|
| 492 | + $sqs_objects[$name.'_'.$parsedView]['populate_list'] = $field['field_list']; |
|
| 493 | + $sqs_objects[$name.'_'.$parsedView]['field_list'] = $field['populate_list']; |
|
| 494 | 494 | } |
| 495 | 495 | } |
| 496 | 496 | } else { |
| 497 | 497 | if ($field['type'] == 'parent') { |
| 498 | - $sqs_objects[$name . '_' . $parsedView] = $qsd->getQSParent(); |
|
| 498 | + $sqs_objects[$name.'_'.$parsedView] = $qsd->getQSParent(); |
|
| 499 | 499 | } |
| 500 | 500 | } //if-else |
| 501 | 501 | } //foreach |
| 502 | 502 | |
| 503 | 503 | foreach ($sqs_objects as $name => $field) { |
| 504 | 504 | foreach ($field['populate_list'] as $key => $fieldname) { |
| 505 | - $sqs_objects[$name]['populate_list'][$key] = $sqs_objects[$name]['populate_list'][$key] . '_' . $parsedView; |
|
| 505 | + $sqs_objects[$name]['populate_list'][$key] = $sqs_objects[$name]['populate_list'][$key].'_'.$parsedView; |
|
| 506 | 506 | } |
| 507 | 507 | } |
| 508 | 508 | } else { |
@@ -514,25 +514,25 @@ discard block |
||
| 514 | 514 | |
| 515 | 515 | $field = $defs[$f['name']]; |
| 516 | 516 | if ($view === 'ConvertLead') { |
| 517 | - $field['name'] = $module . $field['name']; |
|
| 517 | + $field['name'] = $module.$field['name']; |
|
| 518 | 518 | if (isset($field['module']) && |
| 519 | 519 | isset($field['id_name']) && |
| 520 | 520 | substr($field['id_name'], -4) === '_ida' |
| 521 | 521 | ) { |
| 522 | 522 | $lc_module = strtolower($field['module']); |
| 523 | - $ida_suffix = '_' . $lc_module . $lc_module . '_ida'; |
|
| 524 | - if (preg_match('/' . $ida_suffix . '$/', $field['id_name']) > 0) { |
|
| 525 | - $field['id_name'] = $module . $field['id_name']; |
|
| 523 | + $ida_suffix = '_'.$lc_module.$lc_module.'_ida'; |
|
| 524 | + if (preg_match('/'.$ida_suffix.'$/', $field['id_name']) > 0) { |
|
| 525 | + $field['id_name'] = $module.$field['id_name']; |
|
| 526 | 526 | } else { |
| 527 | - $field['id_name'] = $field['name'] . '_' . $field['id_name']; |
|
| 527 | + $field['id_name'] = $field['name'].'_'.$field['id_name']; |
|
| 528 | 528 | } |
| 529 | 529 | } else { |
| 530 | 530 | if (!empty($field['id_name'])) { |
| 531 | - $field['id_name'] = $module . $field['id_name']; |
|
| 531 | + $field['id_name'] = $module.$field['id_name']; |
|
| 532 | 532 | } |
| 533 | 533 | } |
| 534 | 534 | } |
| 535 | - $name = $qsd->form_name . '_' . $field['name']; |
|
| 535 | + $name = $qsd->form_name.'_'.$field['name']; |
|
| 536 | 536 | |
| 537 | 537 | |
| 538 | 538 | if ($field['type'] === 'relate' && isset($field['module']) && (preg_match('/_name$|_c$/si', |
@@ -632,7 +632,7 @@ discard block |
||
| 632 | 632 | for ($j = 0; $j < $totalFields; $j++) { |
| 633 | 633 | //search for the same couple (field_list_item,populate_field_item) |
| 634 | 634 | $field_list_item = $field['field_list'][$j]; |
| 635 | - $field_list_item_alternate = $qsd->form_name . '_' . $field['field_list'][$j]; |
|
| 635 | + $field_list_item_alternate = $qsd->form_name.'_'.$field['field_list'][$j]; |
|
| 636 | 636 | $populate_list_item = $field['populate_list'][$j]; |
| 637 | 637 | $found = false; |
| 638 | 638 | $totalSqsObjects = count($sqs_objects[$name]['field_list']); |
@@ -667,7 +667,7 @@ discard block |
||
| 667 | 667 | $quicksearch_js .= "sqs_objects['$sqsfield']={$json->encode($sqsfieldArray)};"; |
| 668 | 668 | } |
| 669 | 669 | |
| 670 | - return $quicksearch_js . '</script>'; |
|
| 670 | + return $quicksearch_js.'</script>'; |
|
| 671 | 671 | } |
| 672 | 672 | |
| 673 | 673 | return ''; |
@@ -60,21 +60,21 @@ discard block |
||
| 60 | 60 | function __construct ($definition) |
| 61 | 61 | { |
| 62 | 62 | |
| 63 | - parent::__construct ( $definition ) ; |
|
| 64 | - $onetomanyDef = array_merge($definition, array( |
|
| 65 | - 'rhs_label' => isset($definition['lhs_label']) ? $definition['lhs_label'] : null, |
|
| 66 | - 'lhs_label' => isset($definition['rhs_label']) ? $definition['rhs_label'] : null, |
|
| 67 | - 'lhs_subpanel' => isset($definition['rhs_subpanel']) ? $definition['rhs_subpanel'] : null, |
|
| 68 | - 'rhs_subpanel' => isset($definition['lhs_subpanel']) ? $definition['lhs_subpanel'] : null, |
|
| 69 | - 'lhs_module' => isset($definition['rhs_module']) ? $definition['rhs_module'] : null, |
|
| 70 | - 'lhs_table' => isset($definition['rhs_table']) ? $definition['rhs_table'] : null, |
|
| 71 | - 'lhs_key' => isset($definition['rhs_key']) ? $definition['rhs_key'] : null, |
|
| 72 | - 'rhs_module' => isset($definition['lhs_module']) ? $definition['lhs_module'] : null, |
|
| 73 | - 'rhs_table' => isset($definition['lhs_table']) ? $definition['lhs_table'] : null, |
|
| 74 | - 'rhs_key' => isset($definition['lhs_key']) ? $definition['lhs_key'] : null, |
|
| 75 | - 'join_key_lhs' => isset($definition['join_key_rhs']) ? $definition['join_key_rhs'] : null, |
|
| 76 | - 'join_key_rhs' => isset($definition['join_key_lhs']) ? $definition['join_key_lhs'] : null, |
|
| 77 | - 'relationship_type' => MB_ONETOMANY, |
|
| 63 | + parent::__construct ( $definition ) ; |
|
| 64 | + $onetomanyDef = array_merge($definition, array( |
|
| 65 | + 'rhs_label' => isset($definition['lhs_label']) ? $definition['lhs_label'] : null, |
|
| 66 | + 'lhs_label' => isset($definition['rhs_label']) ? $definition['rhs_label'] : null, |
|
| 67 | + 'lhs_subpanel' => isset($definition['rhs_subpanel']) ? $definition['rhs_subpanel'] : null, |
|
| 68 | + 'rhs_subpanel' => isset($definition['lhs_subpanel']) ? $definition['lhs_subpanel'] : null, |
|
| 69 | + 'lhs_module' => isset($definition['rhs_module']) ? $definition['rhs_module'] : null, |
|
| 70 | + 'lhs_table' => isset($definition['rhs_table']) ? $definition['rhs_table'] : null, |
|
| 71 | + 'lhs_key' => isset($definition['rhs_key']) ? $definition['rhs_key'] : null, |
|
| 72 | + 'rhs_module' => isset($definition['lhs_module']) ? $definition['lhs_module'] : null, |
|
| 73 | + 'rhs_table' => isset($definition['lhs_table']) ? $definition['lhs_table'] : null, |
|
| 74 | + 'rhs_key' => isset($definition['lhs_key']) ? $definition['lhs_key'] : null, |
|
| 75 | + 'join_key_lhs' => isset($definition['join_key_rhs']) ? $definition['join_key_rhs'] : null, |
|
| 76 | + 'join_key_rhs' => isset($definition['join_key_lhs']) ? $definition['join_key_lhs'] : null, |
|
| 77 | + 'relationship_type' => MB_ONETOMANY, |
|
| 78 | 78 | )); |
| 79 | 79 | $this->one_to_many = new OneToManyRelationship($onetomanyDef); |
| 80 | 80 | } |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | * BUILD methods called during the build |
| 84 | 84 | */ |
| 85 | 85 | |
| 86 | - function buildLabels($update = false) |
|
| 86 | + function buildLabels($update = false) |
|
| 87 | 87 | { |
| 88 | 88 | return $this->one_to_many->buildLabels(); |
| 89 | 89 | } |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | */ |
| 105 | 105 | function buildVardefs ( ) |
| 106 | 106 | { |
| 107 | - return $this->one_to_many->buildVardefs(); |
|
| 107 | + return $this->one_to_many->buildVardefs(); |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | /* |
@@ -130,19 +130,19 @@ discard block |
||
| 130 | 130 | public function setName ($relationshipName) |
| 131 | 131 | { |
| 132 | 132 | parent::setName($relationshipName); |
| 133 | - $this->one_to_many->setname($relationshipName); |
|
| 133 | + $this->one_to_many->setname($relationshipName); |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | public function setReadonly ($set = true) |
| 137 | 137 | { |
| 138 | 138 | parent::setReadonly($set); |
| 139 | - $this->one_to_many->setReadonly(); |
|
| 139 | + $this->one_to_many->setReadonly(); |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | public function delete () |
| 143 | 143 | { |
| 144 | 144 | parent::delete(); |
| 145 | - $this->one_to_many->delete(); |
|
| 145 | + $this->one_to_many->delete(); |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | public function setRelationship_only () |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
|
| 2 | +if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
|
| 3 | 3 | /********************************************************************************* |
| 4 | 4 | * SugarCRM Community Edition is a customer relationship management program developed by |
| 5 | 5 | * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc. |
@@ -39,9 +39,9 @@ discard block |
||
| 39 | 39 | ********************************************************************************/ |
| 40 | 40 | |
| 41 | 41 | |
| 42 | -require_once 'modules/ModuleBuilder/parsers/relationships/AbstractRelationship.php' ; |
|
| 43 | -require_once 'modules/ModuleBuilder/parsers/relationships/OneToManyRelationship.php' ; |
|
| 44 | -require_once 'modules/ModuleBuilder/parsers/constants.php' ; |
|
| 42 | +require_once 'modules/ModuleBuilder/parsers/relationships/AbstractRelationship.php'; |
|
| 43 | +require_once 'modules/ModuleBuilder/parsers/relationships/OneToManyRelationship.php'; |
|
| 44 | +require_once 'modules/ModuleBuilder/parsers/constants.php'; |
|
| 45 | 45 | |
| 46 | 46 | /* |
| 47 | 47 | * Class to manage the metadata for a many-To-one Relationship |
@@ -57,21 +57,21 @@ discard block |
||
| 57 | 57 | * @param array $definition Parameters passed in as array defined in parent::$definitionKeys |
| 58 | 58 | * The lhs_module value is for the One side; the rhs_module value is for the Many |
| 59 | 59 | */ |
| 60 | - function __construct ($definition) |
|
| 60 | + function __construct($definition) |
|
| 61 | 61 | { |
| 62 | 62 | |
| 63 | - parent::__construct ( $definition ) ; |
|
| 63 | + parent::__construct($definition); |
|
| 64 | 64 | $onetomanyDef = array_merge($definition, array( |
| 65 | - 'rhs_label' => isset($definition['lhs_label']) ? $definition['lhs_label'] : null, |
|
| 66 | - 'lhs_label' => isset($definition['rhs_label']) ? $definition['rhs_label'] : null, |
|
| 65 | + 'rhs_label' => isset($definition['lhs_label']) ? $definition['lhs_label'] : null, |
|
| 66 | + 'lhs_label' => isset($definition['rhs_label']) ? $definition['rhs_label'] : null, |
|
| 67 | 67 | 'lhs_subpanel' => isset($definition['rhs_subpanel']) ? $definition['rhs_subpanel'] : null, |
| 68 | 68 | 'rhs_subpanel' => isset($definition['lhs_subpanel']) ? $definition['lhs_subpanel'] : null, |
| 69 | - 'lhs_module' => isset($definition['rhs_module']) ? $definition['rhs_module'] : null, |
|
| 70 | - 'lhs_table' => isset($definition['rhs_table']) ? $definition['rhs_table'] : null, |
|
| 71 | - 'lhs_key' => isset($definition['rhs_key']) ? $definition['rhs_key'] : null, |
|
| 72 | - 'rhs_module' => isset($definition['lhs_module']) ? $definition['lhs_module'] : null, |
|
| 73 | - 'rhs_table' => isset($definition['lhs_table']) ? $definition['lhs_table'] : null, |
|
| 74 | - 'rhs_key' => isset($definition['lhs_key']) ? $definition['lhs_key'] : null, |
|
| 69 | + 'lhs_module' => isset($definition['rhs_module']) ? $definition['rhs_module'] : null, |
|
| 70 | + 'lhs_table' => isset($definition['rhs_table']) ? $definition['rhs_table'] : null, |
|
| 71 | + 'lhs_key' => isset($definition['rhs_key']) ? $definition['rhs_key'] : null, |
|
| 72 | + 'rhs_module' => isset($definition['lhs_module']) ? $definition['lhs_module'] : null, |
|
| 73 | + 'rhs_table' => isset($definition['lhs_table']) ? $definition['lhs_table'] : null, |
|
| 74 | + 'rhs_key' => isset($definition['lhs_key']) ? $definition['lhs_key'] : null, |
|
| 75 | 75 | 'join_key_lhs' => isset($definition['join_key_rhs']) ? $definition['join_key_rhs'] : null, |
| 76 | 76 | 'join_key_rhs' => isset($definition['join_key_lhs']) ? $definition['join_key_lhs'] : null, |
| 77 | 77 | 'relationship_type' => MB_ONETOMANY, |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | * The format is that of TO_MODULE => relationship, FROM_MODULE, FROM_MODULES_SUBPANEL, mimicking the format in the layoutdefs.php |
| 94 | 94 | * @return array An array of subpanel definitions, keyed by the module |
| 95 | 95 | */ |
| 96 | - function buildSubpanelDefinitions () |
|
| 96 | + function buildSubpanelDefinitions() |
|
| 97 | 97 | { |
| 98 | 98 | return $this->one_to_many->buildSubpanelDefinitions(); |
| 99 | 99 | } |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | /* |
| 103 | 103 | * @return array An array of field definitions, ready for the vardefs, keyed by module |
| 104 | 104 | */ |
| 105 | - function buildVardefs ( ) |
|
| 105 | + function buildVardefs( ) |
|
| 106 | 106 | { |
| 107 | 107 | return $this->one_to_many->buildVardefs(); |
| 108 | 108 | } |
@@ -111,41 +111,41 @@ discard block |
||
| 111 | 111 | * Define what fields to add to which modules layouts |
| 112 | 112 | * @return array An array of module => fieldname |
| 113 | 113 | */ |
| 114 | - function buildFieldsToLayouts () |
|
| 114 | + function buildFieldsToLayouts() |
|
| 115 | 115 | { |
| 116 | 116 | if ($this->relationship_only) |
| 117 | - return array () ; |
|
| 117 | + return array(); |
|
| 118 | 118 | |
| 119 | - return array( $this->lhs_module => $this->getValidDBName($this->relationship_name . "_name") ) ; // this must match the name of the relate field from buildVardefs |
|
| 119 | + return array($this->lhs_module => $this->getValidDBName($this->relationship_name."_name")); // this must match the name of the relate field from buildVardefs |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | /* |
| 123 | 123 | * @return array An array of relationship metadata definitions |
| 124 | 124 | */ |
| 125 | - function buildRelationshipMetaData () |
|
| 125 | + function buildRelationshipMetaData() |
|
| 126 | 126 | { |
| 127 | 127 | return $this->one_to_many->buildRelationshipMetaData(); |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | - public function setName ($relationshipName) |
|
| 130 | + public function setName($relationshipName) |
|
| 131 | 131 | { |
| 132 | 132 | parent::setName($relationshipName); |
| 133 | 133 | $this->one_to_many->setname($relationshipName); |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | - public function setReadonly ($set = true) |
|
| 136 | + public function setReadonly($set = true) |
|
| 137 | 137 | { |
| 138 | 138 | parent::setReadonly($set); |
| 139 | 139 | $this->one_to_many->setReadonly(); |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | - public function delete () |
|
| 142 | + public function delete() |
|
| 143 | 143 | { |
| 144 | 144 | parent::delete(); |
| 145 | 145 | $this->one_to_many->delete(); |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | - public function setRelationship_only () |
|
| 148 | + public function setRelationship_only() |
|
| 149 | 149 | { |
| 150 | 150 | parent::setRelationship_only(); |
| 151 | 151 | $this->one_to_many->setRelationship_only(); |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | die('Not A Valid Entry Point'); |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | -function getModuleFields($module, $view='EditView', $value = '', $valid = array()) |
|
| 45 | +function getModuleFields($module, $view = 'EditView', $value = '', $valid = array()) |
|
| 46 | 46 | { |
| 47 | 47 | global $app_strings, $beanList, $current_user; |
| 48 | 48 | |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | $blockedModuleFields[$mod->module_dir] |
| 80 | 80 | ) && !$current_user->isAdmin() |
| 81 | 81 | ) { |
| 82 | - $GLOBALS['log']->debug('hiding ' . $arr['name'] . ' field from ' . $current_user->name); |
|
| 82 | + $GLOBALS['log']->debug('hiding '.$arr['name'].' field from '.$current_user->name); |
|
| 83 | 83 | continue; |
| 84 | 84 | } |
| 85 | 85 | } |
@@ -107,44 +107,44 @@ discard block |
||
| 107 | 107 | } |
| 108 | 108 | } |
| 109 | 109 | asort($fields); |
| 110 | - if($view == 'JSON'){ |
|
| 110 | + if ($view == 'JSON') { |
|
| 111 | 111 | return json_encode($fields); |
| 112 | 112 | } |
| 113 | - if($view == 'EditView'){ |
|
| 113 | + if ($view == 'EditView') { |
|
| 114 | 114 | return get_select_options_with_id($fields, $value); |
| 115 | 115 | } else { |
| 116 | 116 | return $fields[$value]; |
| 117 | 117 | } |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | -function getRelModuleFields($module, $rel_field, $view='EditView',$value = ''){ |
|
| 120 | +function getRelModuleFields($module, $rel_field, $view = 'EditView', $value = '') { |
|
| 121 | 121 | global $beanList; |
| 122 | 122 | |
| 123 | - if($module == $rel_field){ |
|
| 123 | + if ($module == $rel_field) { |
|
| 124 | 124 | return getModuleFields($module, $view, $value); |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | $mod = new $beanList[$module](); |
| 128 | 128 | $data = $mod->field_defs[$rel_field]; |
| 129 | 129 | |
| 130 | - if(isset($data['module']) && $data['module'] != ''){ |
|
| 130 | + if (isset($data['module']) && $data['module'] != '') { |
|
| 131 | 131 | return getModuleFields($data['module'], $view, $value); |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | -function getRelatedModule($module, $rel_field){ |
|
| 136 | +function getRelatedModule($module, $rel_field) { |
|
| 137 | 137 | global $beanList; |
| 138 | 138 | |
| 139 | - if($module == $rel_field){ |
|
| 139 | + if ($module == $rel_field) { |
|
| 140 | 140 | return $module; |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | $mod = new $beanList[$module](); |
| 144 | 144 | |
| 145 | - if(isset($arr['module']) && $arr['module'] != '') { |
|
| 145 | + if (isset($arr['module']) && $arr['module'] != '') { |
|
| 146 | 146 | return $arr['module']; |
| 147 | - } else if($mod->load_relationship($rel_field)){ |
|
| 147 | + } else if ($mod->load_relationship($rel_field)) { |
|
| 148 | 148 | return $mod->$rel_field->getRelatedModuleName(); |
| 149 | 149 | } |
| 150 | 150 | |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | -function getModuleTreeData($module){ |
|
| 155 | +function getModuleTreeData($module) { |
|
| 156 | 156 | global $beanList, $app_list_strings; |
| 157 | 157 | |
| 158 | 158 | $sort_fields = array(); |
@@ -165,33 +165,33 @@ discard block |
||
| 165 | 165 | ); |
| 166 | 166 | |
| 167 | 167 | if ($module != '') { |
| 168 | - if(isset($beanList[$module]) && $beanList[$module]){ |
|
| 168 | + if (isset($beanList[$module]) && $beanList[$module]) { |
|
| 169 | 169 | $mod = new $beanList[$module](); |
| 170 | 170 | |
| 171 | - foreach($mod->get_linked_fields() as $name => $arr){ |
|
| 172 | - if(isset($arr['module']) && $arr['module'] != '') { |
|
| 171 | + foreach ($mod->get_linked_fields() as $name => $arr) { |
|
| 172 | + if (isset($arr['module']) && $arr['module'] != '') { |
|
| 173 | 173 | $rel_module = $arr['module']; |
| 174 | - } else if($mod->load_relationship($name)){ |
|
| 174 | + } else if ($mod->load_relationship($name)) { |
|
| 175 | 175 | $rel_module = $mod->$name->getRelatedModuleName(); |
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | $rel_module_label = isset($app_list_strings['moduleList'][$rel_module]) ? $app_list_strings['moduleList'][$rel_module] : $rel_module; |
| 179 | - if(isset($arr['vname']) && $arr['vname'] != '') { |
|
| 180 | - $label = $rel_module_label . ' : ' . translate($arr['vname'], $mod->module_dir); |
|
| 181 | - $module_label = trim(translate($arr['vname'],$mod->module_dir),':'); |
|
| 182 | - }else { |
|
| 183 | - $label = $rel_module_label . ' : '. $name; |
|
| 179 | + if (isset($arr['vname']) && $arr['vname'] != '') { |
|
| 180 | + $label = $rel_module_label.' : '.translate($arr['vname'], $mod->module_dir); |
|
| 181 | + $module_label = trim(translate($arr['vname'], $mod->module_dir), ':'); |
|
| 182 | + } else { |
|
| 183 | + $label = $rel_module_label.' : '.$name; |
|
| 184 | 184 | $module_label = $name; |
| 185 | 185 | } |
| 186 | - $sort_fields[$name] = array('label'=>$label,'type'=>'relationship','module' => $rel_module,'module_label'=>$module_label); |
|
| 187 | - if($arr['type'] == 'relate' && isset($arr['id_name']) && $arr['id_name'] != ''){ |
|
| 188 | - if(isset($fields[$arr['id_name']])){ |
|
| 189 | - unset( $fields[$arr['id_name']]); |
|
| 186 | + $sort_fields[$name] = array('label'=>$label, 'type'=>'relationship', 'module' => $rel_module, 'module_label'=>$module_label); |
|
| 187 | + if ($arr['type'] == 'relate' && isset($arr['id_name']) && $arr['id_name'] != '') { |
|
| 188 | + if (isset($fields[$arr['id_name']])) { |
|
| 189 | + unset($fields[$arr['id_name']]); |
|
| 190 | 190 | } |
| 191 | 191 | } |
| 192 | 192 | } //End loop. |
| 193 | - uasort($sort_fields,function($a,$b){ |
|
| 194 | - return strcmp($a['label'],$b['label']); |
|
| 193 | + uasort($sort_fields, function($a, $b) { |
|
| 194 | + return strcmp($a['label'], $b['label']); |
|
| 195 | 195 | }); |
| 196 | 196 | |
| 197 | 197 | $fields = array_merge((array)$fields, (array)$sort_fields); |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | return json_encode($fields); |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | -function getModuleRelationships($module, $view='EditView',$value = '') |
|
| 204 | +function getModuleRelationships($module, $view = 'EditView', $value = '') |
|
| 205 | 205 | { |
| 206 | 206 | global $beanList, $app_list_strings; |
| 207 | 207 | |
@@ -210,27 +210,27 @@ discard block |
||
| 210 | 210 | $invalid_modules = array(); |
| 211 | 211 | |
| 212 | 212 | if ($module != '') { |
| 213 | - if(isset($beanList[$module]) && $beanList[$module]){ |
|
| 213 | + if (isset($beanList[$module]) && $beanList[$module]) { |
|
| 214 | 214 | $mod = new $beanList[$module](); |
| 215 | 215 | |
| 216 | 216 | /*if($mod->is_AuditEnabled()){ |
| 217 | 217 | $fields['Audit'] = translate('LBL_AUDIT_TABLE','AOR_Fields'); |
| 218 | 218 | }*/ |
| 219 | - foreach($mod->get_linked_fields() as $name => $arr){ |
|
| 220 | - if(isset($arr['module']) && $arr['module'] != '') { |
|
| 219 | + foreach ($mod->get_linked_fields() as $name => $arr) { |
|
| 220 | + if (isset($arr['module']) && $arr['module'] != '') { |
|
| 221 | 221 | $rel_module = $arr['module']; |
| 222 | - } else if($mod->load_relationship($name)){ |
|
| 222 | + } else if ($mod->load_relationship($name)) { |
|
| 223 | 223 | $rel_module = $mod->$name->getRelatedModuleName(); |
| 224 | 224 | } |
| 225 | - if(!in_array($rel_module,$invalid_modules)){ |
|
| 225 | + if (!in_array($rel_module, $invalid_modules)) { |
|
| 226 | 226 | $relModuleName = isset($app_list_strings['moduleList'][$rel_module]) ? $app_list_strings['moduleList'][$rel_module] : $rel_module; |
| 227 | - if(isset($arr['vname']) && $arr['vname'] != ''){ |
|
| 228 | - $sort_fields[$name] = $relModuleName.' : '.translate($arr['vname'],$mod->module_dir); |
|
| 227 | + if (isset($arr['vname']) && $arr['vname'] != '') { |
|
| 228 | + $sort_fields[$name] = $relModuleName.' : '.translate($arr['vname'], $mod->module_dir); |
|
| 229 | 229 | } else { |
| 230 | - $sort_fields[$name] = $relModuleName.' : '. $name; |
|
| 230 | + $sort_fields[$name] = $relModuleName.' : '.$name; |
|
| 231 | 231 | } |
| 232 | - if($arr['type'] == 'relate' && isset($arr['id_name']) && $arr['id_name'] != ''){ |
|
| 233 | - if(isset($fields[$arr['id_name']])) unset( $fields[$arr['id_name']]); |
|
| 232 | + if ($arr['type'] == 'relate' && isset($arr['id_name']) && $arr['id_name'] != '') { |
|
| 233 | + if (isset($fields[$arr['id_name']])) unset($fields[$arr['id_name']]); |
|
| 234 | 234 | } |
| 235 | 235 | } |
| 236 | 236 | } //End loop. |
@@ -238,26 +238,26 @@ discard block |
||
| 238 | 238 | $fields = array_merge((array)$fields, (array)$sort_fields); |
| 239 | 239 | } |
| 240 | 240 | } |
| 241 | - if($view == 'EditView'){ |
|
| 241 | + if ($view == 'EditView') { |
|
| 242 | 242 | return get_select_options_with_id($fields, $value); |
| 243 | 243 | } else { |
| 244 | 244 | return $fields[$value]; |
| 245 | 245 | } |
| 246 | 246 | } |
| 247 | 247 | |
| 248 | -function getValidFieldsTypes($module, $field){ |
|
| 248 | +function getValidFieldsTypes($module, $field) { |
|
| 249 | 249 | global $beanFiles, $beanList; |
| 250 | 250 | |
| 251 | 251 | require_once($beanFiles[$beanList[$module]]); |
| 252 | 252 | $focus = new $beanList[$module]; |
| 253 | 253 | $vardef = $focus->getFieldDefinition($field); |
| 254 | 254 | |
| 255 | - switch($vardef['type']) { |
|
| 255 | + switch ($vardef['type']) { |
|
| 256 | 256 | case 'double': |
| 257 | 257 | case 'decimal': |
| 258 | 258 | case 'float': |
| 259 | 259 | case 'currency': |
| 260 | - $valid_type = array('double','decimal','float','currency'); |
|
| 260 | + $valid_type = array('double', 'decimal', 'float', 'currency'); |
|
| 261 | 261 | break; |
| 262 | 262 | case 'uint': |
| 263 | 263 | case 'ulong': |
@@ -265,12 +265,12 @@ discard block |
||
| 265 | 265 | case 'short': |
| 266 | 266 | case 'tinyint': |
| 267 | 267 | case 'int': |
| 268 | - $valid_type = array('uint','ulong','long','short','tinyint','int'); |
|
| 268 | + $valid_type = array('uint', 'ulong', 'long', 'short', 'tinyint', 'int'); |
|
| 269 | 269 | break; |
| 270 | 270 | case 'date': |
| 271 | 271 | case 'datetime': |
| 272 | 272 | case 'datetimecombo': |
| 273 | - $valid_type = array('date','datetime', 'datetimecombo'); |
|
| 273 | + $valid_type = array('date', 'datetime', 'datetimecombo'); |
|
| 274 | 274 | break; |
| 275 | 275 | case 'id': |
| 276 | 276 | case 'relate': |
@@ -287,29 +287,29 @@ discard block |
||
| 287 | 287 | } |
| 288 | 288 | |
| 289 | 289 | |
| 290 | -function getModuleField($module, $fieldname, $aow_field, $view='EditView',$value = '', $alt_type = '', $currency_id = '', $params= array()){ |
|
| 290 | +function getModuleField($module, $fieldname, $aow_field, $view = 'EditView', $value = '', $alt_type = '', $currency_id = '', $params = array()) { |
|
| 291 | 291 | global $current_language, $app_strings, $app_list_strings, $current_user, $beanFiles, $beanList; |
| 292 | 292 | |
| 293 | 293 | // use the mod_strings for this module |
| 294 | - $mod_strings = return_module_language($current_language,$module); |
|
| 294 | + $mod_strings = return_module_language($current_language, $module); |
|
| 295 | 295 | |
| 296 | 296 | // set the filename for this control |
| 297 | - $file = create_cache_directory('modules/AOW_WorkFlow/') . $module . $view . $alt_type . $fieldname . '.tpl'; |
|
| 297 | + $file = create_cache_directory('modules/AOW_WorkFlow/').$module.$view.$alt_type.$fieldname.'.tpl'; |
|
| 298 | 298 | |
| 299 | 299 | $displayParams = array(); |
| 300 | 300 | |
| 301 | - if ( !is_file($file) |
|
| 301 | + if (!is_file($file) |
|
| 302 | 302 | || inDeveloperMode() |
| 303 | - || !empty($_SESSION['developerMode']) ) { |
|
| 303 | + || !empty($_SESSION['developerMode'])) { |
|
| 304 | 304 | |
| 305 | - if ( !isset($vardef) ) { |
|
| 305 | + if (!isset($vardef)) { |
|
| 306 | 306 | require_once($beanFiles[$beanList[$module]]); |
| 307 | 307 | $focus = new $beanList[$module]; |
| 308 | 308 | $vardef = $focus->getFieldDefinition($fieldname); |
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | // Bug: check for AOR value SecurityGroups value missing |
| 312 | - if(stristr($fieldname, 'securitygroups') != false && empty($vardef)) { |
|
| 312 | + if (stristr($fieldname, 'securitygroups') != false && empty($vardef)) { |
|
| 313 | 313 | require_once($beanFiles[$beanList['SecurityGroups']]); |
| 314 | 314 | $module = 'SecurityGroups'; |
| 315 | 315 | $focus = new $beanList[$module]; |
@@ -320,36 +320,36 @@ discard block |
||
| 320 | 320 | //$displayParams['formName'] = 'EditView'; |
| 321 | 321 | |
| 322 | 322 | // if this is the id relation field, then don't have a pop-up selector. |
| 323 | - if( $vardef['type'] == 'relate' && $vardef['id_name'] == $vardef['name']) { |
|
| 323 | + if ($vardef['type'] == 'relate' && $vardef['id_name'] == $vardef['name']) { |
|
| 324 | 324 | $vardef['type'] = 'varchar'; |
| 325 | 325 | } |
| 326 | 326 | |
| 327 | - if(isset($vardef['precision'])) unset($vardef['precision']); |
|
| 327 | + if (isset($vardef['precision'])) unset($vardef['precision']); |
|
| 328 | 328 | |
| 329 | 329 | //$vardef['precision'] = $locale->getPrecedentPreference('default_currency_significant_digits', $current_user); |
| 330 | 330 | |
| 331 | 331 | //TODO Fix datetimecomebo |
| 332 | 332 | //temp work around |
| 333 | - if( $vardef['type'] == 'datetimecombo') { |
|
| 333 | + if ($vardef['type'] == 'datetimecombo') { |
|
| 334 | 334 | $vardef['type'] = 'datetime'; |
| 335 | 335 | } |
| 336 | 336 | |
| 337 | 337 | // trim down textbox display |
| 338 | - if( $vardef['type'] == 'text' ) { |
|
| 338 | + if ($vardef['type'] == 'text') { |
|
| 339 | 339 | $vardef['rows'] = 2; |
| 340 | 340 | $vardef['cols'] = 32; |
| 341 | 341 | } |
| 342 | 342 | |
| 343 | 343 | // create the dropdowns for the parent type fields |
| 344 | - if ( $vardef['type'] == 'parent_type' ) { |
|
| 344 | + if ($vardef['type'] == 'parent_type') { |
|
| 345 | 345 | $vardef['type'] = 'enum'; |
| 346 | 346 | } |
| 347 | 347 | |
| 348 | - if($vardef['type'] == 'link'){ |
|
| 348 | + if ($vardef['type'] == 'link') { |
|
| 349 | 349 | $vardef['type'] = 'relate'; |
| 350 | 350 | $vardef['rname'] = 'name'; |
| 351 | 351 | $vardef['id_name'] = $vardef['name'].'_id'; |
| 352 | - if((!isset($vardef['module']) || $vardef['module'] == '') && $focus->load_relationship($vardef['name'])) { |
|
| 352 | + if ((!isset($vardef['module']) || $vardef['module'] == '') && $focus->load_relationship($vardef['name'])) { |
|
| 353 | 353 | $relName = $vardef['name']; |
| 354 | 354 | $vardef['module'] = $focus->$relName->getRelatedModuleName(); |
| 355 | 355 | } |
@@ -357,24 +357,24 @@ discard block |
||
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | //check for $alt_type |
| 360 | - if ( $alt_type != '' ) { |
|
| 360 | + if ($alt_type != '') { |
|
| 361 | 361 | $vardef['type'] = $alt_type; |
| 362 | 362 | } |
| 363 | 363 | |
| 364 | 364 | // remove the special text entry field function 'getEmailAddressWidget' |
| 365 | - if ( isset($vardef['function']) |
|
| 366 | - && ( $vardef['function'] == 'getEmailAddressWidget' |
|
| 367 | - || $vardef['function']['name'] == 'getEmailAddressWidget' ) ) |
|
| 365 | + if (isset($vardef['function']) |
|
| 366 | + && ($vardef['function'] == 'getEmailAddressWidget' |
|
| 367 | + || $vardef['function']['name'] == 'getEmailAddressWidget')) |
|
| 368 | 368 | unset($vardef['function']); |
| 369 | 369 | |
| 370 | - if(isset($vardef['name']) && ($vardef['name'] == 'date_entered' || $vardef['name'] == 'date_modified')){ |
|
| 370 | + if (isset($vardef['name']) && ($vardef['name'] == 'date_entered' || $vardef['name'] == 'date_modified')) { |
|
| 371 | 371 | $vardef['name'] = 'aow_temp_date'; |
| 372 | 372 | } |
| 373 | 373 | |
| 374 | 374 | // load SugarFieldHandler to render the field tpl file |
| 375 | 375 | static $sfh; |
| 376 | 376 | |
| 377 | - if(!isset($sfh)) { |
|
| 377 | + if (!isset($sfh)) { |
|
| 378 | 378 | require_once('include/SugarFields/SugarFieldHandler.php'); |
| 379 | 379 | $sfh = new SugarFieldHandler(); |
| 380 | 380 | } |
@@ -384,17 +384,17 @@ discard block |
||
| 384 | 384 | // Remove all the copyright comments |
| 385 | 385 | $contents = preg_replace('/\{\*[^\}]*?\*\}/', '', $contents); |
| 386 | 386 | |
| 387 | - if( $view == 'EditView' && ($vardef['type'] == 'relate' || $vardef['type'] == 'parent')){ |
|
| 388 | - $contents = str_replace('"'.$vardef['id_name'].'"','{/literal}"{$fields.'.$vardef['name'].'.id_name}"{literal}', $contents); |
|
| 389 | - $contents = str_replace('"'.$vardef['name'].'"','{/literal}"{$fields.'.$vardef['name'].'.name}"{literal}', $contents); |
|
| 387 | + if ($view == 'EditView' && ($vardef['type'] == 'relate' || $vardef['type'] == 'parent')) { |
|
| 388 | + $contents = str_replace('"'.$vardef['id_name'].'"', '{/literal}"{$fields.'.$vardef['name'].'.id_name}"{literal}', $contents); |
|
| 389 | + $contents = str_replace('"'.$vardef['name'].'"', '{/literal}"{$fields.'.$vardef['name'].'.name}"{literal}', $contents); |
|
| 390 | 390 | } |
| 391 | 391 | |
| 392 | 392 | // hack to disable one of the js calls in this control |
| 393 | - if ( isset($vardef['function']) && ( $vardef['function'] == 'getCurrencyDropDown' || $vardef['function']['name'] == 'getCurrencyDropDown' ) ) |
|
| 393 | + if (isset($vardef['function']) && ($vardef['function'] == 'getCurrencyDropDown' || $vardef['function']['name'] == 'getCurrencyDropDown')) |
|
| 394 | 394 | $contents .= "{literal}<script>function CurrencyConvertAll() { return; }</script>{/literal}"; |
| 395 | 395 | |
| 396 | 396 | // Save it to the cache file |
| 397 | - if($fh = @sugar_fopen($file, 'w')) { |
|
| 397 | + if ($fh = @sugar_fopen($file, 'w')) { |
|
| 398 | 398 | fputs($fh, $contents); |
| 399 | 399 | fclose($fh); |
| 400 | 400 | } |
@@ -411,51 +411,51 @@ discard block |
||
| 411 | 411 | $ss->assign('TIME_FORMAT', $time_format); |
| 412 | 412 | $time_separator = ":"; |
| 413 | 413 | $match = array(); |
| 414 | - if(preg_match('/\d+([^\d])\d+([^\d]*)/s', $time_format, $match)) { |
|
| 414 | + if (preg_match('/\d+([^\d])\d+([^\d]*)/s', $time_format, $match)) { |
|
| 415 | 415 | $time_separator = $match[1]; |
| 416 | 416 | } |
| 417 | 417 | $t23 = strpos($time_format, '23') !== false ? '%H' : '%I'; |
| 418 | - if(!isset($match[2]) || $match[2] == '') { |
|
| 419 | - $ss->assign('CALENDAR_FORMAT', $date_format . ' ' . $t23 . $time_separator . "%M"); |
|
| 418 | + if (!isset($match[2]) || $match[2] == '') { |
|
| 419 | + $ss->assign('CALENDAR_FORMAT', $date_format.' '.$t23.$time_separator."%M"); |
|
| 420 | 420 | } |
| 421 | 421 | else { |
| 422 | 422 | $pm = $match[2] == "pm" ? "%P" : "%p"; |
| 423 | - $ss->assign('CALENDAR_FORMAT', $date_format . ' ' . $t23 . $time_separator . "%M" . $pm); |
|
| 423 | + $ss->assign('CALENDAR_FORMAT', $date_format.' '.$t23.$time_separator."%M".$pm); |
|
| 424 | 424 | } |
| 425 | 425 | |
| 426 | 426 | $ss->assign('CALENDAR_FDOW', $current_user->get_first_day_of_week()); |
| 427 | 427 | |
| 428 | 428 | // populate the fieldlist from the vardefs |
| 429 | 429 | $fieldlist = array(); |
| 430 | - if ( !isset($focus) || !($focus instanceof SugarBean) ) |
|
| 430 | + if (!isset($focus) || !($focus instanceof SugarBean)) |
|
| 431 | 431 | require_once($beanFiles[$beanList[$module]]); |
| 432 | 432 | $focus = new $beanList[$module]; |
| 433 | 433 | // create the dropdowns for the parent type fields |
| 434 | 434 | $vardefFields = $focus->getFieldDefinitions(); |
| 435 | - if (isset($vardefFields[$fieldname]['type']) && $vardefFields[$fieldname]['type'] == 'parent_type' ) { |
|
| 435 | + if (isset($vardefFields[$fieldname]['type']) && $vardefFields[$fieldname]['type'] == 'parent_type') { |
|
| 436 | 436 | $focus->field_defs[$fieldname]['options'] = $focus->field_defs[$vardefFields[$fieldname]['group']]['options']; |
| 437 | 437 | } |
| 438 | - foreach ( $vardefFields as $name => $properties ) { |
|
| 438 | + foreach ($vardefFields as $name => $properties) { |
|
| 439 | 439 | $fieldlist[$name] = $properties; |
| 440 | 440 | // fill in enums |
| 441 | - if(isset($fieldlist[$name]['options']) && is_string($fieldlist[$name]['options']) && isset($app_list_strings[$fieldlist[$name]['options']])) |
|
| 441 | + if (isset($fieldlist[$name]['options']) && is_string($fieldlist[$name]['options']) && isset($app_list_strings[$fieldlist[$name]['options']])) |
|
| 442 | 442 | $fieldlist[$name]['options'] = $app_list_strings[$fieldlist[$name]['options']]; |
| 443 | 443 | // Bug 32626: fall back on checking the mod_strings if not in the app_list_strings |
| 444 | - elseif(isset($fieldlist[$name]['options']) && is_string($fieldlist[$name]['options']) && isset($mod_strings[$fieldlist[$name]['options']])) |
|
| 444 | + elseif (isset($fieldlist[$name]['options']) && is_string($fieldlist[$name]['options']) && isset($mod_strings[$fieldlist[$name]['options']])) |
|
| 445 | 445 | $fieldlist[$name]['options'] = $mod_strings[$fieldlist[$name]['options']]; |
| 446 | 446 | // Bug 22730: make sure all enums have the ability to select blank as the default value. |
| 447 | - if(!isset($fieldlist[$name]['options'][''])) |
|
| 447 | + if (!isset($fieldlist[$name]['options'][''])) |
|
| 448 | 448 | $fieldlist[$name]['options'][''] = ''; |
| 449 | 449 | } |
| 450 | 450 | |
| 451 | 451 | // fill in function return values |
| 452 | - if ( !in_array($fieldname,array('email1','email2')) ) |
|
| 452 | + if (!in_array($fieldname, array('email1', 'email2'))) |
|
| 453 | 453 | { |
| 454 | 454 | if (!empty($fieldlist[$fieldname]['function']['returns']) && $fieldlist[$fieldname]['function']['returns'] == 'html') |
| 455 | 455 | { |
| 456 | 456 | $function = $fieldlist[$fieldname]['function']['name']; |
| 457 | 457 | // include various functions required in the various vardefs |
| 458 | - if ( isset($fieldlist[$fieldname]['function']['include']) && is_file($fieldlist[$fieldname]['function']['include'])) |
|
| 458 | + if (isset($fieldlist[$fieldname]['function']['include']) && is_file($fieldlist[$fieldname]['function']['include'])) |
|
| 459 | 459 | require_once($fieldlist[$fieldname]['function']['include']); |
| 460 | 460 | $_REQUEST[$fieldname] = $value; |
| 461 | 461 | $value = $function($focus, $fieldname, $value, $view); |
@@ -464,40 +464,40 @@ discard block |
||
| 464 | 464 | } |
| 465 | 465 | } |
| 466 | 466 | |
| 467 | - if(isset($fieldlist[$fieldname]['type']) && $fieldlist[$fieldname]['type'] == 'link'){ |
|
| 467 | + if (isset($fieldlist[$fieldname]['type']) && $fieldlist[$fieldname]['type'] == 'link') { |
|
| 468 | 468 | $fieldlist[$fieldname]['id_name'] = $fieldlist[$fieldname]['name'].'_id'; |
| 469 | 469 | |
| 470 | - if((!isset($fieldlist[$fieldname]['module']) || $fieldlist[$fieldname]['module'] == '') && $focus->load_relationship($fieldlist[$fieldname]['name'])) { |
|
| 470 | + if ((!isset($fieldlist[$fieldname]['module']) || $fieldlist[$fieldname]['module'] == '') && $focus->load_relationship($fieldlist[$fieldname]['name'])) { |
|
| 471 | 471 | $relName = $fieldlist[$fieldname]['name']; |
| 472 | 472 | $fieldlist[$fieldname]['module'] = $focus->$relName->getRelatedModuleName(); |
| 473 | 473 | } |
| 474 | 474 | } |
| 475 | 475 | |
| 476 | - if(isset($fieldlist[$fieldname]['name']) && ($fieldlist[$fieldname]['name'] == 'date_entered' || $fieldlist[$fieldname]['name'] == 'date_modified')){ |
|
| 476 | + if (isset($fieldlist[$fieldname]['name']) && ($fieldlist[$fieldname]['name'] == 'date_entered' || $fieldlist[$fieldname]['name'] == 'date_modified')) { |
|
| 477 | 477 | $fieldlist[$fieldname]['name'] = 'aow_temp_date'; |
| 478 | 478 | $fieldlist['aow_temp_date'] = $fieldlist[$fieldname]; |
| 479 | 479 | $fieldname = 'aow_temp_date'; |
| 480 | 480 | } |
| 481 | 481 | |
| 482 | 482 | $quicksearch_js = ''; |
| 483 | - if(isset( $fieldlist[$fieldname]['id_name'] ) && $fieldlist[$fieldname]['id_name'] != '' && $fieldlist[$fieldname]['id_name'] != $fieldlist[$fieldname]['name']){ |
|
| 483 | + if (isset($fieldlist[$fieldname]['id_name']) && $fieldlist[$fieldname]['id_name'] != '' && $fieldlist[$fieldname]['id_name'] != $fieldlist[$fieldname]['name']) { |
|
| 484 | 484 | $rel_value = $value; |
| 485 | 485 | |
| 486 | 486 | require_once("include/TemplateHandler/TemplateHandler.php"); |
| 487 | 487 | $template_handler = new TemplateHandler(); |
| 488 | - $quicksearch_js = $template_handler->createQuickSearchCode($fieldlist,$fieldlist,$view); |
|
| 488 | + $quicksearch_js = $template_handler->createQuickSearchCode($fieldlist, $fieldlist, $view); |
|
| 489 | 489 | $quicksearch_js = str_replace($fieldname, $aow_field.'_display', $quicksearch_js); |
| 490 | 490 | $quicksearch_js = str_replace($fieldlist[$fieldname]['id_name'], $aow_field, $quicksearch_js); |
| 491 | 491 | |
| 492 | 492 | echo $quicksearch_js; |
| 493 | 493 | |
| 494 | - if(isset($fieldlist[$fieldname]['module']) && $fieldlist[$fieldname]['module'] == 'Users'){ |
|
| 494 | + if (isset($fieldlist[$fieldname]['module']) && $fieldlist[$fieldname]['module'] == 'Users') { |
|
| 495 | 495 | $rel_value = get_assigned_user_name($value); |
| 496 | - } else if(isset($fieldlist[$fieldname]['module'])){ |
|
| 496 | + } else if (isset($fieldlist[$fieldname]['module'])) { |
|
| 497 | 497 | require_once($beanFiles[$beanList[$fieldlist[$fieldname]['module']]]); |
| 498 | 498 | $rel_focus = new $beanList[$fieldlist[$fieldname]['module']]; |
| 499 | 499 | $rel_focus->retrieve($value); |
| 500 | - if(isset($fieldlist[$fieldname]['rname']) && $fieldlist[$fieldname]['rname'] != ''){ |
|
| 500 | + if (isset($fieldlist[$fieldname]['rname']) && $fieldlist[$fieldname]['rname'] != '') { |
|
| 501 | 501 | $relDisplayField = $fieldlist[$fieldname]['rname']; |
| 502 | 502 | } else { |
| 503 | 503 | $relDisplayField = 'name'; |
@@ -510,17 +510,17 @@ discard block |
||
| 510 | 510 | $fieldlist[$fieldname]['id_name'] = $aow_field; |
| 511 | 511 | $fieldlist[$fieldlist[$fieldname]['id_name']]['name'] = $aow_field; |
| 512 | 512 | $fieldlist[$fieldname]['name'] = $aow_field.'_display'; |
| 513 | - } else if(isset( $fieldlist[$fieldname]['type'] ) && $view == 'DetailView' && ($fieldlist[$fieldname]['type'] == 'datetimecombo' || $fieldlist[$fieldname]['type'] == 'datetime' || $fieldlist[$fieldname]['type'] == 'date')){ |
|
| 513 | + } else if (isset($fieldlist[$fieldname]['type']) && $view == 'DetailView' && ($fieldlist[$fieldname]['type'] == 'datetimecombo' || $fieldlist[$fieldname]['type'] == 'datetime' || $fieldlist[$fieldname]['type'] == 'date')) { |
|
| 514 | 514 | $value = $focus->convertField($value, $fieldlist[$fieldname]); |
| 515 | - if(!empty($params['date_format']) && isset($params['date_format'])){ |
|
| 515 | + if (!empty($params['date_format']) && isset($params['date_format'])) { |
|
| 516 | 516 | $convert_format = "Y-m-d H:i:s"; |
| 517 | - if($fieldlist[$fieldname]['type'] == 'date') $convert_format = "Y-m-d"; |
|
| 517 | + if ($fieldlist[$fieldname]['type'] == 'date') $convert_format = "Y-m-d"; |
|
| 518 | 518 | $fieldlist[$fieldname]['value'] = $timedate->to_display($value, $convert_format, $params['date_format']); |
| 519 | - }else{ |
|
| 519 | + } else { |
|
| 520 | 520 | $fieldlist[$fieldname]['value'] = $timedate->to_display_date_time($value, true, true); |
| 521 | 521 | } |
| 522 | 522 | $fieldlist[$fieldname]['name'] = $aow_field; |
| 523 | - } else if(isset( $fieldlist[$fieldname]['type'] ) && ($fieldlist[$fieldname]['type'] == 'datetimecombo' || $fieldlist[$fieldname]['type'] == 'datetime' || $fieldlist[$fieldname]['type'] == 'date')){ |
|
| 523 | + } else if (isset($fieldlist[$fieldname]['type']) && ($fieldlist[$fieldname]['type'] == 'datetimecombo' || $fieldlist[$fieldname]['type'] == 'datetime' || $fieldlist[$fieldname]['type'] == 'date')) { |
|
| 524 | 524 | $value = $focus->convertField($value, $fieldlist[$fieldname]); |
| 525 | 525 | $fieldlist[$fieldname]['value'] = $timedate->to_display_date($value); |
| 526 | 526 | //$fieldlist[$fieldname]['value'] = $timedate->to_display_date_time($value, true, true); |
@@ -532,17 +532,17 @@ discard block |
||
| 532 | 532 | |
| 533 | 533 | } |
| 534 | 534 | |
| 535 | - if(isset($fieldlist[$fieldname]['type']) && $fieldlist[$fieldname]['type'] == 'currency' && $view != 'EditView'){ |
|
| 535 | + if (isset($fieldlist[$fieldname]['type']) && $fieldlist[$fieldname]['type'] == 'currency' && $view != 'EditView') { |
|
| 536 | 536 | static $sfh; |
| 537 | 537 | |
| 538 | - if(!isset($sfh)) { |
|
| 538 | + if (!isset($sfh)) { |
|
| 539 | 539 | require_once('include/SugarFields/SugarFieldHandler.php'); |
| 540 | 540 | $sfh = new SugarFieldHandler(); |
| 541 | 541 | } |
| 542 | 542 | |
| 543 | - if($currency_id != '' && !stripos($fieldname, '_USD')){ |
|
| 543 | + if ($currency_id != '' && !stripos($fieldname, '_USD')) { |
|
| 544 | 544 | $userCurrencyId = $current_user->getPreference('currency'); |
| 545 | - if($currency_id != $userCurrencyId){ |
|
| 545 | + if ($currency_id != $userCurrencyId) { |
|
| 546 | 546 | $currency = new Currency(); |
| 547 | 547 | $currency->retrieve($currency_id); |
| 548 | 548 | $value = $currency->convertToDollar($value); |
@@ -557,9 +557,9 @@ discard block |
||
| 557 | 557 | } |
| 558 | 558 | |
| 559 | 559 | $ss->assign("QS_JS", $quicksearch_js); |
| 560 | - $ss->assign("fields",$fieldlist); |
|
| 561 | - $ss->assign("form_name",$view); |
|
| 562 | - $ss->assign("bean",$focus); |
|
| 560 | + $ss->assign("fields", $fieldlist); |
|
| 561 | + $ss->assign("form_name", $view); |
|
| 562 | + $ss->assign("bean", $focus); |
|
| 563 | 563 | |
| 564 | 564 | // add in any additional strings |
| 565 | 565 | $ss->assign("MOD", $mod_strings); |
@@ -572,7 +572,7 @@ discard block |
||
| 572 | 572 | |
| 573 | 573 | |
| 574 | 574 | |
| 575 | -function getDateField($module, $aow_field, $view, $value, $field_option = true){ |
|
| 575 | +function getDateField($module, $aow_field, $view, $value, $field_option = true) { |
|
| 576 | 576 | global $app_list_strings; |
| 577 | 577 | |
| 578 | 578 | // set $view = 'EditView' as default |
@@ -582,21 +582,21 @@ discard block |
||
| 582 | 582 | |
| 583 | 583 | $value = json_decode(html_entity_decode_utf8($value), true); |
| 584 | 584 | |
| 585 | - if(!file_exists('modules/AOBH_BusinessHours/AOBH_BusinessHours.php')) unset($app_list_strings['aow_date_type_list']['business_hours']); |
|
| 585 | + if (!file_exists('modules/AOBH_BusinessHours/AOBH_BusinessHours.php')) unset($app_list_strings['aow_date_type_list']['business_hours']); |
|
| 586 | 586 | |
| 587 | 587 | $field = ''; |
| 588 | 588 | |
| 589 | - if($view == 'EditView'){ |
|
| 590 | - $field .= "<select type='text' name='$aow_field".'[0]'."' id='$aow_field".'[0]'."' title='' tabindex='116'>". getDateFields($module, $view, $value[0], $field_option) ."</select> "; |
|
| 591 | - $field .= "<select type='text' name='$aow_field".'[1]'."' id='$aow_field".'[1]'."' onchange='date_field_change(\"$aow_field\")' title='' tabindex='116'>". get_select_options_with_id($app_list_strings['aow_date_operator'], $value[1]) ."</select> "; |
|
| 589 | + if ($view == 'EditView') { |
|
| 590 | + $field .= "<select type='text' name='$aow_field".'[0]'."' id='$aow_field".'[0]'."' title='' tabindex='116'>".getDateFields($module, $view, $value[0], $field_option)."</select> "; |
|
| 591 | + $field .= "<select type='text' name='$aow_field".'[1]'."' id='$aow_field".'[1]'."' onchange='date_field_change(\"$aow_field\")' title='' tabindex='116'>".get_select_options_with_id($app_list_strings['aow_date_operator'], $value[1])."</select> "; |
|
| 592 | 592 | $display = 'none'; |
| 593 | - if($value[1] == 'plus' || $value[1] == 'minus') $display = ''; |
|
| 593 | + if ($value[1] == 'plus' || $value[1] == 'minus') $display = ''; |
|
| 594 | 594 | $field .= "<input type='text' style='display:$display' name='$aow_field".'[2]'."' id='$aow_field".'[2]'."' title='' value='$value[2]' tabindex='116'> "; |
| 595 | - $field .= "<select type='text' style='display:$display' name='$aow_field".'[3]'."' id='$aow_field".'[3]'."' title='' tabindex='116'>". get_select_options_with_id($app_list_strings['aow_date_type_list'], $value[3]) ."</select>"; |
|
| 595 | + $field .= "<select type='text' style='display:$display' name='$aow_field".'[3]'."' id='$aow_field".'[3]'."' title='' tabindex='116'>".get_select_options_with_id($app_list_strings['aow_date_type_list'], $value[3])."</select>"; |
|
| 596 | 596 | } |
| 597 | 597 | else { |
| 598 | 598 | $field = getDateFields($module, $view, $value[0], $field_option).' '.$app_list_strings['aow_date_operator'][$value[1]]; |
| 599 | - if($value[1] == 'plus' || $value[1] == 'minus'){ |
|
| 599 | + if ($value[1] == 'plus' || $value[1] == 'minus') { |
|
| 600 | 600 | $field .= ' '.$value[2].' '.$app_list_strings['aow_date_type_list'][$value[3]]; |
| 601 | 601 | } |
| 602 | 602 | } |
@@ -604,21 +604,21 @@ discard block |
||
| 604 | 604 | |
| 605 | 605 | } |
| 606 | 606 | |
| 607 | -function getDateFields($module, $view='EditView',$value = '', $field_option = true) |
|
| 607 | +function getDateFields($module, $view = 'EditView', $value = '', $field_option = true) |
|
| 608 | 608 | { |
| 609 | 609 | global $beanList, $app_list_strings; |
| 610 | 610 | |
| 611 | 611 | $fields = $app_list_strings['aow_date_options']; |
| 612 | 612 | |
| 613 | - if(!$field_option) unset($fields['field']); |
|
| 613 | + if (!$field_option) unset($fields['field']); |
|
| 614 | 614 | |
| 615 | 615 | if ($module != '') { |
| 616 | - if(isset($beanList[$module]) && $beanList[$module]){ |
|
| 616 | + if (isset($beanList[$module]) && $beanList[$module]) { |
|
| 617 | 617 | $mod = new $beanList[$module](); |
| 618 | - foreach($mod->field_defs as $name => $arr){ |
|
| 619 | - if($arr['type'] == 'date' || $arr['type'] == 'datetime' || $arr['type'] == 'datetimecombo'){ |
|
| 620 | - if(isset($arr['vname']) && $arr['vname'] != ''){ |
|
| 621 | - $fields[$name] = translate($arr['vname'],$mod->module_dir); |
|
| 618 | + foreach ($mod->field_defs as $name => $arr) { |
|
| 619 | + if ($arr['type'] == 'date' || $arr['type'] == 'datetime' || $arr['type'] == 'datetimecombo') { |
|
| 620 | + if (isset($arr['vname']) && $arr['vname'] != '') { |
|
| 621 | + $fields[$name] = translate($arr['vname'], $mod->module_dir); |
|
| 622 | 622 | } else { |
| 623 | 623 | $fields[$name] = $name; |
| 624 | 624 | } |
@@ -627,42 +627,42 @@ discard block |
||
| 627 | 627 | |
| 628 | 628 | } |
| 629 | 629 | } |
| 630 | - if($view == 'EditView'){ |
|
| 630 | + if ($view == 'EditView') { |
|
| 631 | 631 | return get_select_options_with_id($fields, $value); |
| 632 | 632 | } else { |
| 633 | 633 | return $fields[$value]; |
| 634 | 634 | } |
| 635 | 635 | } |
| 636 | 636 | |
| 637 | -function getAssignField($aow_field, $view, $value){ |
|
| 637 | +function getAssignField($aow_field, $view, $value) { |
|
| 638 | 638 | global $app_list_strings; |
| 639 | 639 | |
| 640 | 640 | $value = json_decode(html_entity_decode_utf8($value), true); |
| 641 | 641 | |
| 642 | - $roles = get_bean_select_array(true, 'ACLRole','name', '','name',true); |
|
| 642 | + $roles = get_bean_select_array(true, 'ACLRole', 'name', '', 'name', true); |
|
| 643 | 643 | |
| 644 | - if(!file_exists('modules/SecurityGroups/SecurityGroup.php')){ |
|
| 644 | + if (!file_exists('modules/SecurityGroups/SecurityGroup.php')) { |
|
| 645 | 645 | unset($app_list_strings['aow_assign_options']['security_group']); |
| 646 | 646 | } |
| 647 | - else{ |
|
| 648 | - $securityGroups = get_bean_select_array(true, 'SecurityGroup','name', '','name',true); |
|
| 647 | + else { |
|
| 648 | + $securityGroups = get_bean_select_array(true, 'SecurityGroup', 'name', '', 'name', true); |
|
| 649 | 649 | } |
| 650 | 650 | |
| 651 | 651 | $field = ''; |
| 652 | 652 | |
| 653 | - if($view == 'EditView'){ |
|
| 654 | - $field .= "<select type='text' name='$aow_field".'[0]'."' id='$aow_field".'[0]'."' onchange='assign_field_change(\"$aow_field\")' title='' tabindex='116'>". get_select_options_with_id($app_list_strings['aow_assign_options'], $value[0]) ."</select> "; |
|
| 655 | - if(!file_exists('modules/SecurityGroups/SecurityGroup.php')){ |
|
| 653 | + if ($view == 'EditView') { |
|
| 654 | + $field .= "<select type='text' name='$aow_field".'[0]'."' id='$aow_field".'[0]'."' onchange='assign_field_change(\"$aow_field\")' title='' tabindex='116'>".get_select_options_with_id($app_list_strings['aow_assign_options'], $value[0])."</select> "; |
|
| 655 | + if (!file_exists('modules/SecurityGroups/SecurityGroup.php')) { |
|
| 656 | 656 | $field .= "<input type='hidden' name='$aow_field".'[1]'."' id='$aow_field".'[1]'."' value='' />"; |
| 657 | 657 | } |
| 658 | 658 | else { |
| 659 | 659 | $display = 'none'; |
| 660 | - if($value[0] == 'security_group') $display = ''; |
|
| 661 | - $field .= "<select type='text' style='display:$display' name='$aow_field".'[1]'."' id='$aow_field".'[1]'."' title='' tabindex='116'>". get_select_options_with_id($securityGroups, $value[1]) ."</select> "; |
|
| 660 | + if ($value[0] == 'security_group') $display = ''; |
|
| 661 | + $field .= "<select type='text' style='display:$display' name='$aow_field".'[1]'."' id='$aow_field".'[1]'."' title='' tabindex='116'>".get_select_options_with_id($securityGroups, $value[1])."</select> "; |
|
| 662 | 662 | } |
| 663 | 663 | $display = 'none'; |
| 664 | - if($value[0] == 'role' || $value[0] == 'security_group') $display = ''; |
|
| 665 | - $field .= "<select type='text' style='display:$display' name='$aow_field".'[2]'."' id='$aow_field".'[2]'."' title='' tabindex='116'>". get_select_options_with_id($roles, $value[2]) ."</select> "; |
|
| 664 | + if ($value[0] == 'role' || $value[0] == 'security_group') $display = ''; |
|
| 665 | + $field .= "<select type='text' style='display:$display' name='$aow_field".'[2]'."' id='$aow_field".'[2]'."' title='' tabindex='116'>".get_select_options_with_id($roles, $value[2])."</select> "; |
|
| 666 | 666 | } |
| 667 | 667 | else { |
| 668 | 668 | $field = $app_list_strings['aow_assign_options'][$value[1]]; |
@@ -674,10 +674,10 @@ discard block |
||
| 674 | 674 | function getDropdownList($list_id, $selected_value) { |
| 675 | 675 | global $app_list_strings; |
| 676 | 676 | $option = ''; |
| 677 | - foreach($app_list_strings[$list_id] as $key => $value) { |
|
| 678 | - if(base64_decode($selected_value) == $key) { |
|
| 677 | + foreach ($app_list_strings[$list_id] as $key => $value) { |
|
| 678 | + if (base64_decode($selected_value) == $key) { |
|
| 679 | 679 | $option .= '<option value="'.$key.'" selected>'.$value.'</option>'; |
| 680 | - } else if($selected_value == $key) { |
|
| 680 | + } else if ($selected_value == $key) { |
|
| 681 | 681 | $option .= '<option value="'.$key.'" selected>'.$value.'</option>'; |
| 682 | 682 | } |
| 683 | 683 | else { |
@@ -688,7 +688,7 @@ discard block |
||
| 688 | 688 | } |
| 689 | 689 | function getLeastBusyUser($users, $field, SugarBean $bean) { |
| 690 | 690 | $counts = array(); |
| 691 | - foreach($users as $id) { |
|
| 691 | + foreach ($users as $id) { |
|
| 692 | 692 | $c = $bean->db->getOne("SELECT count(*) AS c FROM ".$bean->table_name." WHERE $field = '$id' AND deleted = 0"); |
| 693 | 693 | $counts[$id] = $c; |
| 694 | 694 | } |
@@ -699,21 +699,21 @@ discard block |
||
| 699 | 699 | |
| 700 | 700 | function getRoundRobinUser($users, $id) { |
| 701 | 701 | |
| 702 | - $file = create_cache_directory('modules/AOW_WorkFlow/Users/') . $id . 'lastUser.cache.php'; |
|
| 702 | + $file = create_cache_directory('modules/AOW_WorkFlow/Users/').$id.'lastUser.cache.php'; |
|
| 703 | 703 | |
| 704 | - if(isset($_SESSION['lastuser'][$id]) && $_SESSION['lastuser'][$id] != '') { |
|
| 704 | + if (isset($_SESSION['lastuser'][$id]) && $_SESSION['lastuser'][$id] != '') { |
|
| 705 | 705 | $users_by_key = array_flip($users); // now keys are values |
| 706 | 706 | $key = $users_by_key[$_SESSION['lastuser'][$id]] + 1; |
| 707 | - if(!empty($users[$key])) { |
|
| 707 | + if (!empty($users[$key])) { |
|
| 708 | 708 | return $users[$key]; |
| 709 | 709 | } |
| 710 | 710 | } |
| 711 | - else if (is_file($file)){ |
|
| 711 | + else if (is_file($file)) { |
|
| 712 | 712 | require_once($file); |
| 713 | - if(isset($lastUser['User']) && $lastUser['User'] != '') { |
|
| 713 | + if (isset($lastUser['User']) && $lastUser['User'] != '') { |
|
| 714 | 714 | $users_by_key = array_flip($users); // now keys are values |
| 715 | 715 | $key = $users_by_key[$lastUser['User']] + 1; |
| 716 | - if(!empty($users[$key])) { |
|
| 716 | + if (!empty($users[$key])) { |
|
| 717 | 717 | return $users[$key]; |
| 718 | 718 | } |
| 719 | 719 | } |
@@ -726,31 +726,31 @@ discard block |
||
| 726 | 726 | |
| 727 | 727 | $_SESSION['lastuser'][$id] = $user_id; |
| 728 | 728 | |
| 729 | - $file = create_cache_directory('modules/AOW_WorkFlow/Users/') . $id . 'lastUser.cache.php'; |
|
| 729 | + $file = create_cache_directory('modules/AOW_WorkFlow/Users/').$id.'lastUser.cache.php'; |
|
| 730 | 730 | |
| 731 | 731 | $arrayString = var_export_helper(array('User' => $user_id)); |
| 732 | 732 | |
| 733 | - $content =<<<eoq |
|
| 733 | + $content = <<<eoq |
|
| 734 | 734 | <?php |
| 735 | 735 | \$lastUser = {$arrayString}; |
| 736 | 736 | ?> |
| 737 | 737 | eoq; |
| 738 | 738 | |
| 739 | - if($fh = @sugar_fopen($file, 'w')) { |
|
| 739 | + if ($fh = @sugar_fopen($file, 'w')) { |
|
| 740 | 740 | fputs($fh, $content); |
| 741 | 741 | fclose($fh); |
| 742 | 742 | } |
| 743 | 743 | return true; |
| 744 | 744 | } |
| 745 | 745 | |
| 746 | -function getEmailableModules(){ |
|
| 746 | +function getEmailableModules() { |
|
| 747 | 747 | global $beanFiles, $beanList, $app_list_strings; |
| 748 | 748 | $emailableModules = array(); |
| 749 | - foreach($app_list_strings['aow_moduleList'] as $bean_name => $bean_dis) { |
|
| 750 | - if(isset($beanList[$bean_name]) && isset($beanFiles[$beanList[$bean_name]])){ |
|
| 749 | + foreach ($app_list_strings['aow_moduleList'] as $bean_name => $bean_dis) { |
|
| 750 | + if (isset($beanList[$bean_name]) && isset($beanFiles[$beanList[$bean_name]])) { |
|
| 751 | 751 | require_once($beanFiles[$beanList[$bean_name]]); |
| 752 | 752 | $obj = new $beanList[$bean_name]; |
| 753 | - if($obj instanceof Person || $obj instanceof Company){ |
|
| 753 | + if ($obj instanceof Person || $obj instanceof Company) { |
|
| 754 | 754 | $emailableModules[] = $bean_name; |
| 755 | 755 | } |
| 756 | 756 | } |
@@ -759,37 +759,37 @@ discard block |
||
| 759 | 759 | return $emailableModules; |
| 760 | 760 | } |
| 761 | 761 | |
| 762 | -function getRelatedEmailableFields($module){ |
|
| 762 | +function getRelatedEmailableFields($module) { |
|
| 763 | 763 | global $beanList, $app_list_strings; |
| 764 | 764 | $relEmailFields = array(); |
| 765 | 765 | $checked_link = array(); |
| 766 | 766 | $emailableModules = getEmailableModules(); |
| 767 | 767 | if ($module != '') { |
| 768 | - if(isset($beanList[$module]) && $beanList[$module]){ |
|
| 768 | + if (isset($beanList[$module]) && $beanList[$module]) { |
|
| 769 | 769 | $mod = new $beanList[$module](); |
| 770 | 770 | |
| 771 | - foreach($mod->get_related_fields() as $field){ |
|
| 772 | - if(isset($field['link'])) $checked_link[] = $field['link']; |
|
| 773 | - if(!isset($field['module']) || !in_array($field['module'],$emailableModules) || (isset($field['dbType']) && $field['dbType'] == "id")){ |
|
| 771 | + foreach ($mod->get_related_fields() as $field) { |
|
| 772 | + if (isset($field['link'])) $checked_link[] = $field['link']; |
|
| 773 | + if (!isset($field['module']) || !in_array($field['module'], $emailableModules) || (isset($field['dbType']) && $field['dbType'] == "id")) { |
|
| 774 | 774 | continue; |
| 775 | 775 | } |
| 776 | - $relEmailFields[$field['name']] = $field['module'].": ".trim(translate($field['vname'],$mod->module_name),":"); |
|
| 776 | + $relEmailFields[$field['name']] = $field['module'].": ".trim(translate($field['vname'], $mod->module_name), ":"); |
|
| 777 | 777 | } |
| 778 | 778 | |
| 779 | - foreach($mod->get_linked_fields() as $field){ |
|
| 780 | - if(!in_array($field['name'],$checked_link) && !in_array($field['relationship'],$checked_link)){ |
|
| 781 | - if(isset($field['module']) && $field['module'] != '') { |
|
| 779 | + foreach ($mod->get_linked_fields() as $field) { |
|
| 780 | + if (!in_array($field['name'], $checked_link) && !in_array($field['relationship'], $checked_link)) { |
|
| 781 | + if (isset($field['module']) && $field['module'] != '') { |
|
| 782 | 782 | $rel_module = $field['module']; |
| 783 | - } else if($mod->load_relationship($field['name'])){ |
|
| 783 | + } else if ($mod->load_relationship($field['name'])) { |
|
| 784 | 784 | $relField = $field['name']; |
| 785 | 785 | $rel_module = $mod->$relField->getRelatedModuleName(); |
| 786 | 786 | } |
| 787 | 787 | |
| 788 | - if(in_array($rel_module,$emailableModules)) { |
|
| 788 | + if (in_array($rel_module, $emailableModules)) { |
|
| 789 | 789 | if (isset($field['vname']) && $field['vname'] != '') { |
| 790 | - $relEmailFields[$field['name']] = $app_list_strings['moduleList'][$rel_module] . ' : ' . translate($field['vname'], $mod->module_dir); |
|
| 790 | + $relEmailFields[$field['name']] = $app_list_strings['moduleList'][$rel_module].' : '.translate($field['vname'], $mod->module_dir); |
|
| 791 | 791 | } else { |
| 792 | - $relEmailFields[$field['name']] = $app_list_strings['moduleList'][$rel_module] . ' : ' . $field['name']; |
|
| 792 | + $relEmailFields[$field['name']] = $app_list_strings['moduleList'][$rel_module].' : '.$field['name']; |
|
| 793 | 793 | } |
| 794 | 794 | } |
| 795 | 795 | } |
@@ -810,37 +810,37 @@ discard block |
||
| 810 | 810 | |
| 811 | 811 | static $boolean_false_values = array('off', 'false', '0', 'no'); |
| 812 | 812 | |
| 813 | - switch($bean->field_defs[$field]['type']) { |
|
| 813 | + switch ($bean->field_defs[$field]['type']) { |
|
| 814 | 814 | case 'datetime': |
| 815 | 815 | case 'datetimecombo': |
| 816 | - if(empty($value)) break; |
|
| 816 | + if (empty($value)) break; |
|
| 817 | 817 | if ($value == 'NULL') { |
| 818 | 818 | $value = ''; |
| 819 | 819 | break; |
| 820 | 820 | } |
| 821 | - if ( ! preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}$/',$value) ) { |
|
| 821 | + if (!preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}$/', $value)) { |
|
| 822 | 822 | // This appears to be formatted in user date/time |
| 823 | 823 | $value = $timedate->to_db($value); |
| 824 | 824 | } |
| 825 | 825 | break; |
| 826 | 826 | case 'date': |
| 827 | - if(empty($value)) break; |
|
| 827 | + if (empty($value)) break; |
|
| 828 | 828 | if ($value == 'NULL') { |
| 829 | 829 | $value = ''; |
| 830 | 830 | break; |
| 831 | 831 | } |
| 832 | - if ( ! preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/',$value) ) { |
|
| 832 | + if (!preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/', $value)) { |
|
| 833 | 833 | // This date appears to be formatted in the user's format |
| 834 | 834 | $value = $timedate->to_db_date($value, false); |
| 835 | 835 | } |
| 836 | 836 | break; |
| 837 | 837 | case 'time': |
| 838 | - if(empty($value)) break; |
|
| 838 | + if (empty($value)) break; |
|
| 839 | 839 | if ($value == 'NULL') { |
| 840 | 840 | $value = ''; |
| 841 | 841 | break; |
| 842 | 842 | } |
| 843 | - if ( preg_match('/(am|pm)/i',$value) ) { |
|
| 843 | + if (preg_match('/(am|pm)/i', $value)) { |
|
| 844 | 844 | // This time appears to be formatted in the user's format |
| 845 | 845 | $value = $timedate->fromUserTime($value)->format(TimeDate::DB_TIME_FORMAT); |
| 846 | 846 | } |
@@ -849,10 +849,10 @@ discard block |
||
| 849 | 849 | case 'decimal': |
| 850 | 850 | case 'currency': |
| 851 | 851 | case 'float': |
| 852 | - if ( $value === '' || $value == NULL || $value == 'NULL') { |
|
| 852 | + if ($value === '' || $value == NULL || $value == 'NULL') { |
|
| 853 | 853 | continue; |
| 854 | 854 | } |
| 855 | - if ( is_string($value) ) { |
|
| 855 | + if (is_string($value)) { |
|
| 856 | 856 | $value = (float)unformat_number($value); |
| 857 | 857 | } |
| 858 | 858 | break; |
@@ -862,19 +862,19 @@ discard block |
||
| 862 | 862 | case 'short': |
| 863 | 863 | case 'tinyint': |
| 864 | 864 | case 'int': |
| 865 | - if ( $value === '' || $value == NULL || $value == 'NULL') { |
|
| 865 | + if ($value === '' || $value == NULL || $value == 'NULL') { |
|
| 866 | 866 | continue; |
| 867 | 867 | } |
| 868 | - if ( is_string($value) ) { |
|
| 868 | + if (is_string($value)) { |
|
| 869 | 869 | $value = (int)unformat_number($value); |
| 870 | 870 | } |
| 871 | 871 | break; |
| 872 | 872 | case 'bool': |
| 873 | 873 | if (empty($value)) { |
| 874 | 874 | $value = false; |
| 875 | - } else if(true === $value || 1 == $value) { |
|
| 875 | + } else if (true === $value || 1 == $value) { |
|
| 876 | 876 | $value = true; |
| 877 | - } else if(in_array(strval($value), $boolean_false_values)) { |
|
| 877 | + } else if (in_array(strval($value), $boolean_false_values)) { |
|
| 878 | 878 | $value = false; |
| 879 | 879 | } else { |
| 880 | 880 | $value = true; |
@@ -179,7 +179,7 @@ discard block |
||
| 179 | 179 | if(isset($arr['vname']) && $arr['vname'] != '') { |
| 180 | 180 | $label = $rel_module_label . ' : ' . translate($arr['vname'], $mod->module_dir); |
| 181 | 181 | $module_label = trim(translate($arr['vname'],$mod->module_dir),':'); |
| 182 | - }else { |
|
| 182 | + } else { |
|
| 183 | 183 | $label = $rel_module_label . ' : '. $name; |
| 184 | 184 | $module_label = $name; |
| 185 | 185 | } |
@@ -230,7 +230,9 @@ discard block |
||
| 230 | 230 | $sort_fields[$name] = $relModuleName.' : '. $name; |
| 231 | 231 | } |
| 232 | 232 | if($arr['type'] == 'relate' && isset($arr['id_name']) && $arr['id_name'] != ''){ |
| 233 | - if(isset($fields[$arr['id_name']])) unset( $fields[$arr['id_name']]); |
|
| 233 | + if(isset($fields[$arr['id_name']])) { |
|
| 234 | + unset( $fields[$arr['id_name']]); |
|
| 235 | + } |
|
| 234 | 236 | } |
| 235 | 237 | } |
| 236 | 238 | } //End loop. |
@@ -324,7 +326,9 @@ discard block |
||
| 324 | 326 | $vardef['type'] = 'varchar'; |
| 325 | 327 | } |
| 326 | 328 | |
| 327 | - if(isset($vardef['precision'])) unset($vardef['precision']); |
|
| 329 | + if(isset($vardef['precision'])) { |
|
| 330 | + unset($vardef['precision']); |
|
| 331 | + } |
|
| 328 | 332 | |
| 329 | 333 | //$vardef['precision'] = $locale->getPrecedentPreference('default_currency_significant_digits', $current_user); |
| 330 | 334 | |
@@ -364,8 +368,9 @@ discard block |
||
| 364 | 368 | // remove the special text entry field function 'getEmailAddressWidget' |
| 365 | 369 | if ( isset($vardef['function']) |
| 366 | 370 | && ( $vardef['function'] == 'getEmailAddressWidget' |
| 367 | - || $vardef['function']['name'] == 'getEmailAddressWidget' ) ) |
|
| 368 | - unset($vardef['function']); |
|
| 371 | + || $vardef['function']['name'] == 'getEmailAddressWidget' ) ) { |
|
| 372 | + unset($vardef['function']); |
|
| 373 | + } |
|
| 369 | 374 | |
| 370 | 375 | if(isset($vardef['name']) && ($vardef['name'] == 'date_entered' || $vardef['name'] == 'date_modified')){ |
| 371 | 376 | $vardef['name'] = 'aow_temp_date'; |
@@ -390,8 +395,9 @@ discard block |
||
| 390 | 395 | } |
| 391 | 396 | |
| 392 | 397 | // hack to disable one of the js calls in this control |
| 393 | - if ( isset($vardef['function']) && ( $vardef['function'] == 'getCurrencyDropDown' || $vardef['function']['name'] == 'getCurrencyDropDown' ) ) |
|
| 394 | - $contents .= "{literal}<script>function CurrencyConvertAll() { return; }</script>{/literal}"; |
|
| 398 | + if ( isset($vardef['function']) && ( $vardef['function'] == 'getCurrencyDropDown' || $vardef['function']['name'] == 'getCurrencyDropDown' ) ) { |
|
| 399 | + $contents .= "{literal}<script>function CurrencyConvertAll() { return; }</script>{/literal}"; |
|
| 400 | + } |
|
| 395 | 401 | |
| 396 | 402 | // Save it to the cache file |
| 397 | 403 | if($fh = @sugar_fopen($file, 'w')) { |
@@ -417,8 +423,7 @@ discard block |
||
| 417 | 423 | $t23 = strpos($time_format, '23') !== false ? '%H' : '%I'; |
| 418 | 424 | if(!isset($match[2]) || $match[2] == '') { |
| 419 | 425 | $ss->assign('CALENDAR_FORMAT', $date_format . ' ' . $t23 . $time_separator . "%M"); |
| 420 | - } |
|
| 421 | - else { |
|
| 426 | + } else { |
|
| 422 | 427 | $pm = $match[2] == "pm" ? "%P" : "%p"; |
| 423 | 428 | $ss->assign('CALENDAR_FORMAT', $date_format . ' ' . $t23 . $time_separator . "%M" . $pm); |
| 424 | 429 | } |
@@ -427,8 +432,9 @@ discard block |
||
| 427 | 432 | |
| 428 | 433 | // populate the fieldlist from the vardefs |
| 429 | 434 | $fieldlist = array(); |
| 430 | - if ( !isset($focus) || !($focus instanceof SugarBean) ) |
|
| 431 | - require_once($beanFiles[$beanList[$module]]); |
|
| 435 | + if ( !isset($focus) || !($focus instanceof SugarBean) ) { |
|
| 436 | + require_once($beanFiles[$beanList[$module]]); |
|
| 437 | + } |
|
| 432 | 438 | $focus = new $beanList[$module]; |
| 433 | 439 | // create the dropdowns for the parent type fields |
| 434 | 440 | $vardefFields = $focus->getFieldDefinitions(); |
@@ -438,14 +444,17 @@ discard block |
||
| 438 | 444 | foreach ( $vardefFields as $name => $properties ) { |
| 439 | 445 | $fieldlist[$name] = $properties; |
| 440 | 446 | // fill in enums |
| 441 | - if(isset($fieldlist[$name]['options']) && is_string($fieldlist[$name]['options']) && isset($app_list_strings[$fieldlist[$name]['options']])) |
|
| 442 | - $fieldlist[$name]['options'] = $app_list_strings[$fieldlist[$name]['options']]; |
|
| 447 | + if(isset($fieldlist[$name]['options']) && is_string($fieldlist[$name]['options']) && isset($app_list_strings[$fieldlist[$name]['options']])) { |
|
| 448 | + $fieldlist[$name]['options'] = $app_list_strings[$fieldlist[$name]['options']]; |
|
| 449 | + } |
|
| 443 | 450 | // Bug 32626: fall back on checking the mod_strings if not in the app_list_strings |
| 444 | - elseif(isset($fieldlist[$name]['options']) && is_string($fieldlist[$name]['options']) && isset($mod_strings[$fieldlist[$name]['options']])) |
|
| 445 | - $fieldlist[$name]['options'] = $mod_strings[$fieldlist[$name]['options']]; |
|
| 451 | + elseif(isset($fieldlist[$name]['options']) && is_string($fieldlist[$name]['options']) && isset($mod_strings[$fieldlist[$name]['options']])) { |
|
| 452 | + $fieldlist[$name]['options'] = $mod_strings[$fieldlist[$name]['options']]; |
|
| 453 | + } |
|
| 446 | 454 | // Bug 22730: make sure all enums have the ability to select blank as the default value. |
| 447 | - if(!isset($fieldlist[$name]['options'][''])) |
|
| 448 | - $fieldlist[$name]['options'][''] = ''; |
|
| 455 | + if(!isset($fieldlist[$name]['options'][''])) { |
|
| 456 | + $fieldlist[$name]['options'][''] = ''; |
|
| 457 | + } |
|
| 449 | 458 | } |
| 450 | 459 | |
| 451 | 460 | // fill in function return values |
@@ -455,8 +464,9 @@ discard block |
||
| 455 | 464 | { |
| 456 | 465 | $function = $fieldlist[$fieldname]['function']['name']; |
| 457 | 466 | // include various functions required in the various vardefs |
| 458 | - if ( isset($fieldlist[$fieldname]['function']['include']) && is_file($fieldlist[$fieldname]['function']['include'])) |
|
| 459 | - require_once($fieldlist[$fieldname]['function']['include']); |
|
| 467 | + if ( isset($fieldlist[$fieldname]['function']['include']) && is_file($fieldlist[$fieldname]['function']['include'])) { |
|
| 468 | + require_once($fieldlist[$fieldname]['function']['include']); |
|
| 469 | + } |
|
| 460 | 470 | $_REQUEST[$fieldname] = $value; |
| 461 | 471 | $value = $function($focus, $fieldname, $value, $view); |
| 462 | 472 | |
@@ -514,9 +524,11 @@ discard block |
||
| 514 | 524 | $value = $focus->convertField($value, $fieldlist[$fieldname]); |
| 515 | 525 | if(!empty($params['date_format']) && isset($params['date_format'])){ |
| 516 | 526 | $convert_format = "Y-m-d H:i:s"; |
| 517 | - if($fieldlist[$fieldname]['type'] == 'date') $convert_format = "Y-m-d"; |
|
| 527 | + if($fieldlist[$fieldname]['type'] == 'date') { |
|
| 528 | + $convert_format = "Y-m-d"; |
|
| 529 | + } |
|
| 518 | 530 | $fieldlist[$fieldname]['value'] = $timedate->to_display($value, $convert_format, $params['date_format']); |
| 519 | - }else{ |
|
| 531 | + } else{ |
|
| 520 | 532 | $fieldlist[$fieldname]['value'] = $timedate->to_display_date_time($value, true, true); |
| 521 | 533 | } |
| 522 | 534 | $fieldlist[$fieldname]['name'] = $aow_field; |
@@ -582,7 +594,9 @@ discard block |
||
| 582 | 594 | |
| 583 | 595 | $value = json_decode(html_entity_decode_utf8($value), true); |
| 584 | 596 | |
| 585 | - if(!file_exists('modules/AOBH_BusinessHours/AOBH_BusinessHours.php')) unset($app_list_strings['aow_date_type_list']['business_hours']); |
|
| 597 | + if(!file_exists('modules/AOBH_BusinessHours/AOBH_BusinessHours.php')) { |
|
| 598 | + unset($app_list_strings['aow_date_type_list']['business_hours']); |
|
| 599 | + } |
|
| 586 | 600 | |
| 587 | 601 | $field = ''; |
| 588 | 602 | |
@@ -590,11 +604,12 @@ discard block |
||
| 590 | 604 | $field .= "<select type='text' name='$aow_field".'[0]'."' id='$aow_field".'[0]'."' title='' tabindex='116'>". getDateFields($module, $view, $value[0], $field_option) ."</select> "; |
| 591 | 605 | $field .= "<select type='text' name='$aow_field".'[1]'."' id='$aow_field".'[1]'."' onchange='date_field_change(\"$aow_field\")' title='' tabindex='116'>". get_select_options_with_id($app_list_strings['aow_date_operator'], $value[1]) ."</select> "; |
| 592 | 606 | $display = 'none'; |
| 593 | - if($value[1] == 'plus' || $value[1] == 'minus') $display = ''; |
|
| 607 | + if($value[1] == 'plus' || $value[1] == 'minus') { |
|
| 608 | + $display = ''; |
|
| 609 | + } |
|
| 594 | 610 | $field .= "<input type='text' style='display:$display' name='$aow_field".'[2]'."' id='$aow_field".'[2]'."' title='' value='$value[2]' tabindex='116'> "; |
| 595 | 611 | $field .= "<select type='text' style='display:$display' name='$aow_field".'[3]'."' id='$aow_field".'[3]'."' title='' tabindex='116'>". get_select_options_with_id($app_list_strings['aow_date_type_list'], $value[3]) ."</select>"; |
| 596 | - } |
|
| 597 | - else { |
|
| 612 | + } else { |
|
| 598 | 613 | $field = getDateFields($module, $view, $value[0], $field_option).' '.$app_list_strings['aow_date_operator'][$value[1]]; |
| 599 | 614 | if($value[1] == 'plus' || $value[1] == 'minus'){ |
| 600 | 615 | $field .= ' '.$value[2].' '.$app_list_strings['aow_date_type_list'][$value[3]]; |
@@ -610,7 +625,9 @@ discard block |
||
| 610 | 625 | |
| 611 | 626 | $fields = $app_list_strings['aow_date_options']; |
| 612 | 627 | |
| 613 | - if(!$field_option) unset($fields['field']); |
|
| 628 | + if(!$field_option) { |
|
| 629 | + unset($fields['field']); |
|
| 630 | + } |
|
| 614 | 631 | |
| 615 | 632 | if ($module != '') { |
| 616 | 633 | if(isset($beanList[$module]) && $beanList[$module]){ |
@@ -643,8 +660,7 @@ discard block |
||
| 643 | 660 | |
| 644 | 661 | if(!file_exists('modules/SecurityGroups/SecurityGroup.php')){ |
| 645 | 662 | unset($app_list_strings['aow_assign_options']['security_group']); |
| 646 | - } |
|
| 647 | - else{ |
|
| 663 | + } else{ |
|
| 648 | 664 | $securityGroups = get_bean_select_array(true, 'SecurityGroup','name', '','name',true); |
| 649 | 665 | } |
| 650 | 666 | |
@@ -654,17 +670,19 @@ discard block |
||
| 654 | 670 | $field .= "<select type='text' name='$aow_field".'[0]'."' id='$aow_field".'[0]'."' onchange='assign_field_change(\"$aow_field\")' title='' tabindex='116'>". get_select_options_with_id($app_list_strings['aow_assign_options'], $value[0]) ."</select> "; |
| 655 | 671 | if(!file_exists('modules/SecurityGroups/SecurityGroup.php')){ |
| 656 | 672 | $field .= "<input type='hidden' name='$aow_field".'[1]'."' id='$aow_field".'[1]'."' value='' />"; |
| 657 | - } |
|
| 658 | - else { |
|
| 673 | + } else { |
|
| 659 | 674 | $display = 'none'; |
| 660 | - if($value[0] == 'security_group') $display = ''; |
|
| 675 | + if($value[0] == 'security_group') { |
|
| 676 | + $display = ''; |
|
| 677 | + } |
|
| 661 | 678 | $field .= "<select type='text' style='display:$display' name='$aow_field".'[1]'."' id='$aow_field".'[1]'."' title='' tabindex='116'>". get_select_options_with_id($securityGroups, $value[1]) ."</select> "; |
| 662 | 679 | } |
| 663 | 680 | $display = 'none'; |
| 664 | - if($value[0] == 'role' || $value[0] == 'security_group') $display = ''; |
|
| 681 | + if($value[0] == 'role' || $value[0] == 'security_group') { |
|
| 682 | + $display = ''; |
|
| 683 | + } |
|
| 665 | 684 | $field .= "<select type='text' style='display:$display' name='$aow_field".'[2]'."' id='$aow_field".'[2]'."' title='' tabindex='116'>". get_select_options_with_id($roles, $value[2]) ."</select> "; |
| 666 | - } |
|
| 667 | - else { |
|
| 685 | + } else { |
|
| 668 | 686 | $field = $app_list_strings['aow_assign_options'][$value[1]]; |
| 669 | 687 | } |
| 670 | 688 | return $field; |
@@ -679,8 +697,7 @@ discard block |
||
| 679 | 697 | $option .= '<option value="'.$key.'" selected>'.$value.'</option>'; |
| 680 | 698 | } else if($selected_value == $key) { |
| 681 | 699 | $option .= '<option value="'.$key.'" selected>'.$value.'</option>'; |
| 682 | - } |
|
| 683 | - else { |
|
| 700 | + } else { |
|
| 684 | 701 | $option .= '<option value="'.$key.'">'.$value.'</option>'; |
| 685 | 702 | } |
| 686 | 703 | } |
@@ -707,8 +724,7 @@ discard block |
||
| 707 | 724 | if(!empty($users[$key])) { |
| 708 | 725 | return $users[$key]; |
| 709 | 726 | } |
| 710 | - } |
|
| 711 | - else if (is_file($file)){ |
|
| 727 | + } else if (is_file($file)){ |
|
| 712 | 728 | require_once($file); |
| 713 | 729 | if(isset($lastUser['User']) && $lastUser['User'] != '') { |
| 714 | 730 | $users_by_key = array_flip($users); // now keys are values |
@@ -769,7 +785,9 @@ discard block |
||
| 769 | 785 | $mod = new $beanList[$module](); |
| 770 | 786 | |
| 771 | 787 | foreach($mod->get_related_fields() as $field){ |
| 772 | - if(isset($field['link'])) $checked_link[] = $field['link']; |
|
| 788 | + if(isset($field['link'])) { |
|
| 789 | + $checked_link[] = $field['link']; |
|
| 790 | + } |
|
| 773 | 791 | if(!isset($field['module']) || !in_array($field['module'],$emailableModules) || (isset($field['dbType']) && $field['dbType'] == "id")){ |
| 774 | 792 | continue; |
| 775 | 793 | } |
@@ -813,7 +831,9 @@ discard block |
||
| 813 | 831 | switch($bean->field_defs[$field]['type']) { |
| 814 | 832 | case 'datetime': |
| 815 | 833 | case 'datetimecombo': |
| 816 | - if(empty($value)) break; |
|
| 834 | + if(empty($value)) { |
|
| 835 | + break; |
|
| 836 | + } |
|
| 817 | 837 | if ($value == 'NULL') { |
| 818 | 838 | $value = ''; |
| 819 | 839 | break; |
@@ -824,7 +844,9 @@ discard block |
||
| 824 | 844 | } |
| 825 | 845 | break; |
| 826 | 846 | case 'date': |
| 827 | - if(empty($value)) break; |
|
| 847 | + if(empty($value)) { |
|
| 848 | + break; |
|
| 849 | + } |
|
| 828 | 850 | if ($value == 'NULL') { |
| 829 | 851 | $value = ''; |
| 830 | 852 | break; |
@@ -835,7 +857,9 @@ discard block |
||
| 835 | 857 | } |
| 836 | 858 | break; |
| 837 | 859 | case 'time': |
| 838 | - if(empty($value)) break; |
|
| 860 | + if(empty($value)) { |
|
| 861 | + break; |
|
| 862 | + } |
|
| 839 | 863 | if ($value == 'NULL') { |
| 840 | 864 | $value = ''; |
| 841 | 865 | break; |