From 4820082dd9638304d23e55866673917244a5c8b2 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Wed, 4 May 2005 06:37:02 +0000 Subject: [PATCH] r69: Removing our nasty iff() function in place of the beautiful ternary operator --- admin/global.php | 2 +- admin/options.php | 6 +++--- admin/product.php | 6 +++--- admin/usergroup.php | 10 +++++----- docs/phrasetools.php | 18 +++++++++--------- editreport.php | 14 +++++++------- includes/adminfunctions.php | 24 ++++++++++++------------ includes/functions.php | 14 +++++++------- index.php | 2 +- newreport.php | 4 ++-- search.php | 6 +++--- showreport.php | 4 ++-- 12 files changed, 55 insertions(+), 55 deletions(-) diff --git a/admin/global.php b/admin/global.php index 90d400c..e594b96 100755 --- a/admin/global.php +++ b/admin/global.php @@ -24,7 +24,7 @@ function admin_login() { global $admin, $bugsys; - $admin->page_start('Login', '', 15, '', 'document.cplogin.' . iff($bugsys->userinfo['email'], 'password', 'email') . '.focus();'); + $admin->page_start('Login', '', 15, '', 'document.cplogin.' . (($bugsys->userinfo['email']) ? 'password' : 'email') . '.focus();'); $admin->form_start('../login.php', 'cplogin', false, 'cplogin'); $admin->table_start(true, '425'); diff --git a/admin/options.php b/admin/options.php index dbbf728..e14c791 100755 --- a/admin/options.php +++ b/admin/options.php @@ -79,7 +79,7 @@ if ($_REQUEST['do'] == 'modify') $admin->table_head(phrase('settinggroup_' . $group)); foreach ($settings["$group"] AS $opt) { - $admin->row_span('" . phrase('setting_' . $opt[1] . '_title') . "", 'thead'); + $admin->row_span('" . phrase('setting_' . $opt[1] . '_title') . "", 'thead'); switch ($opt[2]) { case 'textbox': @@ -92,8 +92,8 @@ if ($_REQUEST['do'] == 'modify') $options["$opt[1]"] = $opt[3]; } - $admin->list_item(phrase('yes'), '1', iff($options["$opt[1]"], true, false)); - $admin->list_item(phrase('no'), '0', iff($options["$opt[1]"], false, true)); + $admin->list_item(phrase('yes'), '1', (($options["$opt[1]"]) ? true : false)); + $admin->list_item(phrase('no'), '0', (($options["$opt[1]"]) ? false : true)); $admin->row_list(phrase('setting_' . $opt[1] . '_desc'), 'setting[' . $opt[1] . ']', false); break; diff --git a/admin/product.php b/admin/product.php index b5a28a1..5fd629f 100755 --- a/admin/product.php +++ b/admin/product.php @@ -21,8 +21,8 @@ if (!can_perform('canadminversions')) function construct_option_list($type, $id, $edit, $addcomponent, $addversion, $delete, $displayorder) { $type_display = substr_replace($type, strtoupper($type{0}), 0, 1); - $type = iff($type == 'component', 'product', $type); - $type_action = iff($type == 'version', 'versionid', 'productid'); + $type = (($type == 'component') ? 'product' : $type); + $type_action = (($type == 'version') ? 'versionid' : 'productid'); if ($edit) { @@ -48,7 +48,7 @@ function construct_option_list($type, $id, $edit, $addcomponent, $addversion, $d $name = $type . '_' . $id; - $displayorder = iff($displayorder != -1, ' ', ''); + $displayorder = (($displayorder != -1) ? ' ' : ''); return $displayorder . ' '; } diff --git a/admin/usergroup.php b/admin/usergroup.php index 2a159b5..6814661 100755 --- a/admin/usergroup.php +++ b/admin/usergroup.php @@ -63,14 +63,14 @@ if ($_REQUEST['do'] == 'delete') if ($_REQUEST['do'] == 'add' OR $_REQUEST['do'] == 'edit') { - $add = iff($_REQUEST['do'] == 'add', true, false); - $edit = iff($_REQUEST['do'] == 'edit', true, false); + $add = (($_REQUEST['do'] == 'add') ? true : false); + $edit = (($_REQUEST['do'] == 'edit') ? true : false); sanitize(array('usergroupid' => INT)); - $admin->page_start(iff($add, phrase('new_usergroup'), phrase('edit_usergroup'))); + $admin->page_start((($add, phrase('new_usergroup') ? phrase('edit_usergroup') : '')); - $admin->form_start('usergroup.php', iff($add, 'insert', 'update')); + $admin->form_start('usergroup.php', (($add) ? 'insert' : 'update')); if ($edit) { @@ -237,7 +237,7 @@ if ($_REQUEST['do'] == 'modify') $admin->table_column_head(array(phrase('usergroup'), phrase('number_of_users'), phrase('action'))); foreach ($usergroups AS $group) { - $admin->row_multi_item(array("$group[title]" => 'l', iff(!$group['total'], '-', $group['total']) => 'c', "" . phrase('edit_wraplink') . "" . iff($group['usergroupid'] > 6, "" . phrase('delete_wraplink') . "") => 'c')); + $admin->row_multi_item(array("$group[title]" => 'l', ((!$group['total']) ? '-' : $group['total']) => 'c', "" . phrase('edit_wraplink') . "" . (($group['usergroupid'] > 6) ? "" . phrase('delete_wraplink') . "" : '') => 'c')); } $admin->row_span('', 'tfoot', 'center', 3); diff --git a/docs/phrasetools.php b/docs/phrasetools.php index b39209f..3793c61 100644 --- a/docs/phrasetools.php +++ b/docs/phrasetools.php @@ -23,15 +23,15 @@ define('CHECKED', ' checked="checked"'); sanitize(array('varname' => STR, 'phrasetext' => STR, 'matchmethod' => STR, 'do' => STR, 'doneinsert' => INT, 'oldvarname' => STR)); $use['varname'] = (bool)$_REQUEST['use']['varname']; $use['phrasetext'] = (bool)$_REQUEST['use']['phrasetext']; -$use['and'] = iff($vars['matchmethod'] == 'and', true, false); -$use['or'] = iff($use['and'], false, true); -$use['matcher'] = iff($use['and'], 'AND', 'OR'); - -$select['or'] = iff($use['or'], SELECTED); -$select['and'] = iff($use['and'] , SELECTED); -$select['search'] = iff($vars['do'] == 'search', SELECTED); -$select['insert'] = iff($vars['do'] == 'insert' OR $vars['doneinsert'], SELECTED); -$select['delete'] = iff($vars['do'] == 'delete', SELECTED); +$use['and'] = (($vars['matchmethod'] == 'and') ? true : false); +$use['or'] = (($use['and']) ? false : true); +$use['matcher'] = (($use['and']) ? 'AND' : 'OR'); + +$select['or'] = (($use['or']) ? SELECTED : ''); +$select['and'] = (($use['and']) ? SELECTED : ''); +$select['search'] = (($vars['do'] == 'search') ? SELECTED : ''); +$select['insert'] = (($vars['do'] == 'insert' OR $vars['doneinsert']) ? SELECTED : ''); +$select['delete'] = (($vars['do'] == 'delete') ? SELECTED : ''); function sanitize_name($name) { diff --git a/editreport.php b/editreport.php index 8bd307a..2782d12 100644 --- a/editreport.php +++ b/editreport.php @@ -116,18 +116,18 @@ if ($_REQUEST['do'] == 'edit') foreach ($bugsys->datastore['severity'] AS $severity) { $value = $severity['severityid']; - $selected = iff($severity['severityid'] == $bug['severity'], true, false); + $selected = (($severity['severityid'] == $bug['severity']) ? true : false); $label = $severity['severity']; eval('$select[severity] .= "' . $template->fetch('selectoption') . '";'); } - $show['changestatus'] = iff(can_perform('canchangestatus'), true, false); + $show['changestatus'] = ((can_perform('canchangestatus')) ? true : false); if (can_perform('canchangestatus')) { foreach ($bugsys->datastore['priority'] AS $priority) { $value = $priority['priorityid']; - $selected = iff($priority['priorityid'] == $bug['priority'], true, false); + $selected = (($priority['priorityid'] == $bug['priority']) ? true : false); $label = $priority['priority']; eval('$select[priority] .= "' . $template->fetch('selectoption') . '";'); } @@ -135,7 +135,7 @@ if ($_REQUEST['do'] == 'edit') foreach ($bugsys->datastore['status'] AS $status) { $value = $status['statusid']; - $selected = iff($status['statusid'] == $bug['status'], true, false); + $selected = (($status['statusid'] == $bug['status']) ? true : false); $label = $status['status']; eval('$select[status] .= "' . $template->fetch('selectoption') . '";'); } @@ -143,19 +143,19 @@ if ($_REQUEST['do'] == 'edit') foreach ($bugsys->datastore['resolution'] AS $resolution) { $value = $resolution['resolutionid']; - $selected = iff($resolution['resolutionid'] == $bug['resolution'], true, false); + $selected = (($resolution['resolutionid'] == $bug['resolution']) ? true : false); $label = $resolution['resolution']; eval('$select[resolution] .= "' . $template->fetch('selectoption') . '";'); } } - $show['assign'] = iff(can_perform('canassign'), true, false); + $show['assign'] = ((can_perform('canassign')) ? true : false); if (can_perform('canassign')) { foreach ($bugsys->datastore['assignto'] AS $dev) { $value = $dev['userid']; - $selected = iff($dev['userid'] == $bug['assignedto'], true, false); + $selected = (($dev['userid'] == $bug['assignedto']) ? true : false); $label = construct_user_display($dev, false); eval('$select[dev] .= "' . $template->fetch('selectoption') . '";'); } diff --git a/includes/adminfunctions.php b/includes/adminfunctions.php index 13c2351..2c48514 100755 --- a/includes/adminfunctions.php +++ b/includes/adminfunctions.php @@ -66,12 +66,12 @@ EOD; echo "\r"; echo "\r\t$title"; echo "\r\t"; - echo "\r\t" . iff($extra, "\r$extra"); + echo "\r\t" . (($extra) ? "\r$extra" : ''); if (!defined('HIDE_SETUP')) { echo "\r\t"; } - echo "\r\r\r"; + echo "\r\r\r"; echo "
\r\r\r"; } @@ -133,7 +133,7 @@ EOD; function table_head($title, $colspan = 2, $strong = true) { - echo "\r\t" . iff($strong, "$title", $title) . "\r\r"; + echo "\r\t" . (($strong) ? "$title" : $title) . "\r\r"; } function table_column_head($columnarray) @@ -163,7 +163,7 @@ EOD; // ################################################################### function form_start($action, $do, $enctype = false, $name = 'inputform', $submitmethod = 'post') { - echo "\r\r
\r"; + echo "\r\r\r"; $this->form_hidden_field('do', $do); } @@ -202,7 +202,7 @@ EOD; } } - echo "\r\t$text\r"; + echo "\r\t$text\r"; } function row_multi_item($row_array) @@ -276,12 +276,12 @@ EOD; function row_input($label, $name, $value = '', $colspan = 2, $size = 35, $length = false, $password = false, $lalign = 'top') { - $this->row_text($label, "", $lalign, $colspan); + $this->row_text($label, "", $lalign, $colspan); } function row_textarea($label, $name, $value = '', $colspan = 2, $rows = 7, $cols = 50, $code = false, $style = '') { - $this->row_text($label, "", 'top', $colspan); + $this->row_text($label, "", 'top', $colspan); } function row_tfoot($data, $colspan = 2) @@ -306,11 +306,11 @@ EOD; } else { - $reset = iff($reset, " $reset "); + $reset = (($reset) ? " $reset " : ''); } $output = "\r\t\t"; - $output .= iff($reset, "\r\t\t $extra\r\t"); + $output .= (($reset) ? "\r\t\t $extra\r\t" : ''); $this->row_tfoot($output); } @@ -323,7 +323,7 @@ EOD; { global $listitem; - $listitem[] = "\r\t"; + $listitem[] = "\r\t"; } function row_list($label, $name, $is_jump = true, $colspan = 2) @@ -337,12 +337,12 @@ EOD; $listitem = ''; - $this->row_text($label, "\r" . iff($is_jump, "\r") . "\r", $colspan); + $this->row_text($label, "\r" . (($is_jump) ? "\r" : '') . "\r", $colspan); } function row_yesno($label, $name, $value, $colspan = 2) { - $this->row_text($label, " " . phrase('yes') . " " . phrase('no'), $colspan); + $this->row_text($label, " " . phrase('yes') . " " . phrase('no'), $colspan); } } diff --git a/includes/functions.php b/includes/functions.php index 7221bb9..4e35bf6 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -67,11 +67,11 @@ function construct_option_select($name, $array, $selected = 0, $valuekey = '', $ // if we're not working on a boolean false, we use it for the value (allows -1 and 0) if ($includenil !== false) { - $opts[] = ''; + $opts[] = ''; } foreach ($array AS $value => $label) { - $opts[] = ''; + $opts[] = ''; } return '"; } @@ -94,7 +94,7 @@ function datelike($format, $timestamp) function construct_user_display($userinfo, $userid = true) { fetch_user_display_name($userinfo); - return "$userinfo[displayname]" . iff($userinfo['showemail'], " <$userinfo[email]>") . iff($userid, " (userid: $userinfo[userid])"); + return "$userinfo[displayname]" . (($userinfo['showemail']) ? " <$userinfo[email]>" : '') . (($userid) ? " (userid: $userinfo[userid])" : ''); } // ######################## Start can_perform ######################## @@ -161,7 +161,7 @@ function construct_pcv_select($select = '', $prefix = '    & $row['prefix'] = $prefix . $prefix; $row['value'] = "{$valuepfx}c0v$version[versionid]"; $row['title'] = $version['version']; - $row['selected'] = iff($select == $row['value'], $selected, ''); + $row['selected'] = (($select == $row['value']) ? $selected : ''); eval('$HTML .= "' . $bugsys->template->fetch('pcv_select_row') . '";'); } } @@ -173,7 +173,7 @@ function construct_pcv_select($select = '', $prefix = '    & $row['prefix'] = $prefix; $valuepfx .= "c$component[productid]"; $row['value'] = "{$valuepfx}v0"; - $row['selected'] = iff($select == $row['value'], $selected, ''); + $row['selected'] = (($select == $row['value']) ? $selected : ''); $row['title'] = $component['title']; $row['description'] = ''; eval('$HTML .= "' . $bugsys->template->fetch('pcv_select_row') . '";'); @@ -184,7 +184,7 @@ function construct_pcv_select($select = '', $prefix = '    & { $row['prefix'] = $prefix . $prefix; $row['value'] = "{$valuepfx}v$version[versionid]"; - $row['selected'] = iff($select == $row['value'], $selected, ''); + $row['selected'] = (($select == $row['value']) ? $selected : ''); $row['title'] = $version['version']; $row['description'] = ''; eval('$HTML .= "' . $bugsys->template->fetch('pcv_select_row') . '";'); @@ -208,7 +208,7 @@ function construct_pcv_select_global_version($product = 0, $component = 0, $vers $row['prefix'] = $prefix . $prefix; $row['typeselect'] = $type; $row['value'] = "p{$product}c{$component}v$version[versionid]"; - $row['selected'] = iff($select == $row['value'], ' checked="checked"', ''); + $row['selected'] = (($select == $row['value']) ? ' checked="checked"' : ''); $row['title'] = $version['version']; $row['description'] = ''; eval('$global_versions_html .= "' . $bugsys->template->fetch('pcv_select_row') . '";'); diff --git a/index.php b/index.php index 17a729d..25be5c7 100644 --- a/index.php +++ b/index.php @@ -49,7 +49,7 @@ while ($bug = $db->fetch_array($bugs_fetch)) $db->free_result($bugs_fetch); -$show['newreport'] = iff(can_perform('cansubmitbugs'), true, false); +$show['newreport'] = ((can_perform('cansubmitbugs')) ? true : false); eval('$template->flush("' . $template->fetch('TRACKERHOME') . '");'); diff --git a/newreport.php b/newreport.php index b240ee3..4b7fca8 100755 --- a/newreport.php +++ b/newreport.php @@ -157,7 +157,7 @@ if ($_REQUEST['do'] == 'add') eval('$select[severity] .= "' . $template->fetch('selectoption') . '";'); } - $show['changestatus'] = iff(can_perform('canchangestatus'), true, false); + $show['changestatus'] = ((can_perform('canchangestatus')) ? true : false); if (can_perform('canchangestatus')) { @@ -183,7 +183,7 @@ if ($_REQUEST['do'] == 'add') } } - $show['assign'] = iff(can_perform('canassign'), true, false); + $show['assign'] = ((can_perform('canassign')) ? true : false); if (can_perform('canassign')) { diff --git a/search.php b/search.php index b7d6d93..f0f7da3 100644 --- a/search.php +++ b/search.php @@ -25,9 +25,9 @@ if (!can_perform('cansearch')) } define('MODE', intval($_POST['mode'])); -define('MODE_ANY', iff(MODE == 1, 1, 0)); -define('MODE_ALL', iff(MODE == 2, 1, 0)); -define('MODE_RAW', iff(MODE == 3, 1, 0)); +define('MODE_ANY', ((MODE == 1) ? 1 : 0)); +define('MODE_ALL', ((MODE == 2) ? 1 : 0)); +define('MODE_RAW', ((MODE == 3) ? 1 : 0)); define('SEARCH_WORD_MIN', 3); diff --git a/showreport.php b/showreport.php index 94cd427..38d9904 100644 --- a/showreport.php +++ b/showreport.php @@ -47,7 +47,7 @@ if (!is_array($bug)) // prep display $bug['userinfo'] = construct_user_display($bug); $bug['product'] = $bugsys->datastore['product']["$bug[productid]"]['title']; -$bug['component'] = iff($bug['componentid'], $bugsys->datastore['product']["$bug[componentid]"]['title']); +$bug['component'] = (($bug['componentid']) ? $bugsys->datastore['product']["$bug[componentid]"]['title'] : ''); $bug['version'] = $bugsys->datastore['version']["$bug[versionid]"]['version']; $bug['status'] = $bugsys->datastore['status']["$bug[status]"]['status']; $bug['resolution'] = $bugsys->datastore['resolution']["$bug[resolution]"]['resolution']; @@ -55,7 +55,7 @@ $bug['severity'] = $bugsys->datastore['severity']["$bug[severity]"]['severity']; $bug['priority'] = $bugsys->datastore['priority']["$bug[priority]"]['priority']; $assigninfo = $bugsys->datastore['assignto']["$bug[assignedto]"]; -$bug['assigninfo'] = iff(is_array($assigninfo), construct_user_display($assigninfo)); +$bug['assigninfo'] = ((is_array($assigninfo)) ? construct_user_display($assigninfo) : ''); if (((can_perform('caneditown') AND $bugsys->userinfo['userid'] == $comment['userid']) OR can_perform('caneditothers')) AND can_perform('caneditinfo')) { -- 2.22.5