Support Incident Tracker GIT4.x
html.inc.php
Go to the documentation of this file.
00001 <?php
00002 // html.inc.php - functions that return generic HTML elements, e.g. input boxes
00003 //                or convert plain text to HTML ...
00004 //
00005 // SiT (Support Incident Tracker) - Support call tracking system
00006 // Copyright (C) 2010-2011 The Support Incident Tracker Project
00007 // Copyright (C) 2000-2009 Salford Software Ltd. and Contributors
00008 //
00009 // This software may be used and distributed according to the terms
00010 // of the GNU General Public License, incorporated herein by reference.
00011 
00012 // Prevent script from being run directly (ie. it must always be included
00013 if (realpath(__FILE__) == realpath($_SERVER['SCRIPT_FILENAME']))
00014 {
00015     exit;
00016 }
00017 
00037 function html_redirect($url, $success = TRUE, $message = '', $close = FALSE)
00038 {
00039     global $CONFIG, $headerdisplayed, $siterrors;
00040 
00041     if (!empty($_REQUEST['dashboard']))
00042     {
00043         $headerdisplayed = TRUE;
00044     }
00045 
00046     if (empty($message))
00047     {
00048         $refreshtime = 1;
00049     }
00050     elseif ($success == FALSE)
00051     {
00052         $refreshtime = 3;
00053     }
00054     else
00055     {
00056         $refreshtime = 6;
00057     }
00058 
00059     // Catch all, make refresh time slow if errors are detected
00060     if ($siterrors > 0)
00061     {
00062         $refreshtime = 10;
00063     }
00064 
00065     if ($close === FALSE)
00066     {
00067         $refresh = "{$refreshtime}; url={$url}";
00068     }
00069 
00070     $title = $GLOBALS['strPleaseWaitRedirect'];
00071     if (!$headerdisplayed)
00072     {
00073         if ($_SESSION['portalauth'] == TRUE)
00074         {
00075             include (APPLICATION_INCPATH . 'portalheader.inc.php');
00076         }
00077         else
00078         {
00079             include (APPLICATION_INCPATH . 'htmlheader.inc.php');
00080         }
00081     }
00082 
00083     echo "<h3>";
00084     if ($success)
00085     {
00086         echo "<span class='success'>{$GLOBALS['strSuccess']}</span>";
00087     }
00088     else
00089     {
00090         echo "<span class='failure'>{$GLOBALS['strFailed']}</span>";
00091     }
00092 
00093     if (!empty($message))
00094     {
00095         echo ": {$message}";
00096     }
00097 
00098     echo "</h3>";
00099     if (empty($_REQUEST['dashboard']))
00100     {
00101         echo "<h4>{$GLOBALS['strPleaseWaitRedirect']}</h4>";
00102         if ($headerdisplayed)
00103         {
00104             echo "<p align='center'><a href=\"{$url}\">{$GLOBALS['strContinue']}</a></p>";
00105         }
00106     }
00107 
00108     if ($close)
00109     {
00110         if ($_SESSION['userconfig']['show_confirmation_close_window'] == 'TRUE')
00111         {
00112             ?>
00113             <script type='text/javascript'>
00114             //<![CDATA[
00115 
00116             if (window.confirm(strEmailSentSuccessfullyConfirmWindowClosure))
00117             {
00118                 close_page_redirect('<?php echo $url; ?>');
00119             }
00120 
00121             //]]>
00122             </script>
00123             <?php
00124         }
00125         else
00126         {
00127             // We  use a PeriodicalExecutor as we don't want to close the window instantly, we want users to be able to read the message
00128             ?>
00129             <script type='text/javascript'>
00130             //<![CDATA[
00131 
00132             new PeriodicalExecuter(function(pe) {
00133                                             window.close();
00134                                         },
00135                                         <?php echo $refreshtime ?>);
00136 
00137             //]]>
00138             </script>
00139             <?php
00140         }
00141     }
00142 
00143     // TODO 3.35 Add a link to refresh the dashlet if this is run inside a dashlet
00144 
00145     if ($headerdisplayed)
00146     {
00147         if ($_SESSION['portalauth'] == TRUE)
00148         {
00149             include (APPLICATION_INCPATH . 'htmlfooter.inc.php');
00150         }
00151         else
00152         {
00153             include (APPLICATION_INCPATH . 'htmlfooter.inc.php');
00154         }
00155     }
00156 }
00157 
00158 
00169 function html_checkbox($name, $state, $value ='', $attributes = '')
00170 {
00171 
00172     if ($state === TRUE) $state = 'TRUE';
00173     if ($state === FALSE) $state = 'FALSE';
00174     if ($state === 1 OR $state === 'Yes' OR $state === 'yes' OR
00175         $state === 'true' OR $state === 'TRUE')
00176     {
00177         if ($value == '') $value = $state;
00178         $html = "<input type='checkbox' checked='checked' name='{$name}' id='{$name}' value='{$value}' {$attributes} />" ;
00179     }
00180     else
00181     {
00182         if ($value == '') $value = $state;
00183         $html = "<input type='checkbox' name='{$name}' id='{$name}' value='{$value}' {$attributes} />" ;
00184     }
00185 //     $html .= "(state:$state)";
00186     return $html;
00187 }
00188 
00189 
00199 function gravatar($email, $size = 32, $hyperlink = TRUE)
00200 {
00201     global $CONFIG, $iconset;
00202     $default = $CONFIG['default_gravatar'];
00203 
00204     if (isset( $_SERVER['HTTPS']) && (strtolower( $_SERVER['HTTPS'] ) != 'off' ))
00205     {
00206         // Secure
00207         $grav_url = "https://secure.gravatar.com";
00208     }
00209     else
00210     {
00211         $grav_url = "http://www.gravatar.com";
00212     }
00213     $grav_url .= "/avatar.php?";
00214     $grav_url .= "gravatar_id=".md5(strtolower($email));
00215     $grav_url .= "&amp;default=".urlencode($CONFIG['default_gravatar']);
00216     $grav_url .= "&amp;size=".$size;
00217     $grav_url .= "&amp;rating=G";
00218 
00219     if ($hyperlink) $html = "<a href='http://site.gravatar.com/'>";
00220     $html .= "<img src='{$grav_url}' width='{$size}' height='{$size}' alt='' ";
00221     $html .= "class='gravatar' />";
00222     if ($hyperlink) $html .= "</a>";
00223 
00224     return $html;
00225 }
00226 
00227 
00234 function percent_bar($percent)
00235 {
00236     if ($percent == '') $percent = 0;
00237     if ($percent < 0) $percent = 0;
00238     if ($percent > 100) $percent = 100;
00239     // #B4D6B4;
00240     $html = "<div class='percentcontainer'>";
00241     $html .= "<div class='percentbar' style='width: {$percent}%;'>  {$percent}&#037;";
00242     $html .= "</div></div>\n";
00243     return $html;
00244 }
00245 
00246 
00261 function colheader($colname, $coltitle, $sort = FALSE, $order='', $filter='', $defaultorder='a', $width='')
00262 {
00263     global $CONFIG;
00264     if ($width !=  '')
00265     {
00266         $html = "<th width='".intval($width)."%'>";
00267     }
00268     else
00269     {
00270         $html = "<th>";
00271     }
00272 
00273     $qsappend='';
00274     if (!empty($filter) AND is_array($filter))
00275     {
00276         foreach ($filter AS $key => $var)
00277         {
00278             if ($var != '') $qsappend .= "&amp;{$key}=".urlencode($var);
00279         }
00280     }
00281     else
00282     {
00283         $qsappend = '';
00284     }
00285 
00286     if ($sort == $colname)
00287     {
00288         if ($order == 'a')
00289         {
00290             $html .= "<a href='{$_SERVER['PHP_SELF']}?sort=$colname&amp;order=d{$qsappend}'>{$coltitle}</a> ";
00291             $html .= "<img src='{$CONFIG['application_webpath']}images/sort_a.png' width='5' height='5' alt='{$GLOBALS['strSortAscending']}' /> ";
00292         }
00293         else
00294         {
00295             $html .= "<a href='{$_SERVER['PHP_SELF']}?sort=$colname&amp;order=a{$qsappend}'>{$coltitle}</a> ";
00296             $html .= "<img src='{$CONFIG['application_webpath']}images/sort_d.png' width='5' height='5' alt='{$GLOBALS['strSortDescending']}' /> ";
00297         }
00298     }
00299     else
00300     {
00301         if ($sort === FALSE) $html .= "{$coltitle}";
00302         else $html .= "<a href='{$_SERVER['PHP_SELF']}?sort=$colname&amp;order={$defaultorder}{$qsappend}'>{$coltitle}</a> ";
00303     }
00304     $html .= "</th>";
00305     return $html;
00306 }
00307 
00308 
00331 function user_alert($message, $severity, $helpcontext = '')
00332 {
00333     switch ($severity)
00334     {
00335         case E_USER_ERROR:
00336             $class = 'alert error';
00337             $info = $GLOBALS['strError'];
00338             break;
00339         case E_USER_WARNING:
00340             $class = 'alert warning';
00341             $info = $GLOBALS['strWarning'];
00342             break;
00343         case E_USER_NOTICE:
00344         default:
00345             $class = 'alert info';
00346             $info = $GLOBALS['strInfo'];
00347     }
00348     $html = "<p class='{$class}'>";
00349     if (!empty($helpcontext)) $html .= help_link($helpcontext);
00350     //<strong>{$info}</strong>:
00351     $html .= "{$message}";
00352     $html .= "</p>";
00353 
00354     return $html;
00355 }
00356 
00357 
00369 function icon($filename, $size='', $alt='', $title='', $id='')
00370 {
00371     global $iconset, $CONFIG;
00372 
00373     if (empty($iconset)) $iconset = $_SESSION['userconfig']['iconset'];
00374     $sizes = array(12, 16, 32);
00375 
00376     if (!in_array($size, $sizes) OR empty($size))
00377     {
00378         trigger_error("Incorrect image size for '{$filename}.png' ", E_USER_WARNING);
00379         $size = 16;
00380     }
00381 
00382     $file = dirname( __FILE__ ).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR."images/icons/{$iconset}";
00383     $file .= "/{$size}x{$size}/{$filename}.png";
00384 
00385     $urlpath = "{$CONFIG['application_webpath']}images/icons/{$iconset}";
00386     $urlpath .= "/{$size}x{$size}/{$filename}.png";
00387 
00388     if (!file_exists($file))
00389     {
00390         $alt = "Missing icon: '{$filename}.png', ({$file}) size {$size}";
00391         if ($CONFIG['debug']) trigger_error($alt, E_USER_WARNING);
00392         $urlpath = "{$CONFIG['application_webpath']}/images/icons/sit";
00393         $urlpath .= "/16x16/blank.png";
00394     }
00395     $icon = "<img src=\"{$urlpath}\"";
00396     if (!empty($alt))
00397     {
00398         $icon .= " alt=\"{$alt}\" ";
00399     }
00400     else
00401     {
00402         $alt = $filename;
00403         $icon .= " alt=\"{$alt}\" ";
00404     }
00405     if (!empty($title))
00406     {
00407         $icon .= " title=\"{$title}\"";
00408     }
00409     else
00410     {
00411         $icon .= " title=\"{$alt}\"";
00412     }
00413 
00414     if (!empty($id))
00415     {
00416         $icon .= " id=\"{$id}\"";
00417     }
00418 
00419     $icon .= " width=\"{$size}\" height=\"{$size}\" ";
00420 
00421     $icon .= " />";
00422 
00423     return $icon;
00424 }
00425 
00426 
00433 function date_picker($formelement)
00434 {
00435     global $CONFIG, $iconset;
00436 
00437     $divid = "datediv".str_replace('.','',$formelement);
00438     $html = "<img src='{$CONFIG['application_webpath']}images/icons/{$iconset}/16x16/pickdate.png' ";
00439     $html .= "onmouseup=\"toggleDatePicker('$divid','$formelement')\" width='16' height='16' alt='date picker' style='cursor: pointer; vertical-align: bottom;' />";
00440     $html .= "\n<div id='$divid' style='position: absolute;'></div>\n";
00441     return $html;
00442 }
00443 
00444 
00456 function autocomplete($formelement, $action = 'autocomplete_sitecontact')
00457 {
00458     $html .= "<script type=\"text/javascript\">\n//<![CDATA[\n";
00459     // Disable browser autocomplete (it clashes)
00460     $html .= "$('$formelement').setAttribute(\"autocomplete\", \"off\"); \n";
00461     $html .= "new AutoComplete('{$formelement}', 'ajaxdata.php?action={$action}&s=', {\n";
00462     $html .= "delay: 0.25,\n";
00463     $html .= "resultFormat: AutoComplete.Options.RESULT_FORMAT_JSON\n";
00464     $html .= "}); \n//]]>\n</script>\n";
00465 
00466     return $html;
00467 }
00468 
00469 
00481 function protectform($formelement, $message = '')
00482 {
00483     global $strRememberToSave;
00484     if (empty($message)) $message = $strRememberToSave;
00485     $html = "\n<script type='text/javascript'>\n";
00486     $html .= "  var fp = new FormProtector('$formelement');\n";
00487     $html .= "  fp.setMessage('{$message}');\n";
00488     $html .= "</script>\n";
00489 
00490     return $html;
00491 }
00492 
00493 
00501 function group_selector($selected, $urlargs='')
00502 {
00503     $gsql = "SELECT * FROM `{$GLOBALS['dbGroups']}` ORDER BY name";
00504     $gresult = mysql_query($gsql);
00505     if (mysql_error()) trigger_error(mysql_error(), E_USER_WARNING);
00506     while ($group = mysql_fetch_object($gresult))
00507     {
00508         $grouparr[$group->id] = $group->name;
00509     }
00510     $numgroups = mysql_num_rows($gresult);
00511 
00512     if (!empty($urlargs)) $urlargs = "&amp;{$urlargs}";
00513     if ($numgroups >= 1)
00514     {
00515         echo "<form action='{$_SERVER['PHP_SELF']}?{$urlargs}' class='filterform' method='get'>";
00516         echo "{$GLOBALS['strGroup']}: <select name='choosegroup' onchange='window.location.href=this.options[this.selectedIndex].value'>";
00517         echo "<option value='{$_SERVER['PHP_SELF']}?gid=all{$urlargs}'";
00518         if ($selected == 'all') echo " selected='selected'";
00519         echo ">{$GLOBALS['strAll']}</option>\n";
00520         echo "<option value='{$_SERVER['PHP_SELF']}?gid=allonline{$urlargs}'";
00521         if ($selected == 'allonline') echo " selected='selected'";
00522         echo ">{$GLOBALS['strAllOnline']}</option>\n";
00523         foreach ($grouparr AS $groupid => $groupname)
00524         {
00525             echo "<option value='{$_SERVER['PHP_SELF']}?gid={$groupid}{$urlargs}'";
00526             if ($groupid == $selected) echo " selected='selected'";
00527             echo ">{$groupname}</option>\n";
00528         }
00529         echo "<option value='{$_SERVER['PHP_SELF']}?gid=0{$urlargs}'";
00530         if ($selected === '0') echo " selected='selected'";
00531         echo ">{$GLOBALS['strUsersNoGroup']}</option>\n";
00532         echo "</select>\n";
00533         echo "</form>\n";
00534     }
00535 
00536     return $numgroups;
00537 }
00538 
00539 
00548 function draw_tabs($tabsarray, $selected='', $divclass='tabcontainer')
00549 {
00550     if ($selected == '') $selected = key($tabsarray);
00551     $html .= "<div class='{$divclass}'>";
00552     $html .= "<ul>";
00553     foreach ($tabsarray AS $tab => $url)
00554     {
00555         $html .= "<li";
00556         if (strtolower($tab) == strtolower($selected))
00557         {
00558             $html .= " class='active'";
00559         }
00560         $html .= ">";
00561         $tab = str_replace('_', ' ', $tab);
00562         $html .= "<a href='{$url}'>$tab</a></li>\n";
00563     }
00564     $html .= "</ul>";
00565     $html .= "</div>";
00566 
00567     return $html;
00568 }
00569 
00570 
00577 function bbcode($text)
00578 {
00579     global $CONFIG;
00580     $bbcode_regex = array(0 => "/\[b\](.*?)\[\/b\]/s",
00581                         1 => "/\[i\](.*?)\[\/i\]/s",
00582                         2 => "/\[u\](.*?)\[\/u\]/s",
00583                         3 => "/\[quote\](.*?)\[\/quote\]/s",
00584                         4 => "/\[size=(.+?)\](.+?)\[\/size\]/is",
00585                         5 => "/\[url\](.*?)\[\/url\]/s",
00586                         6 => "/\[size=(.+?)\](.+?)\[\/size\]/is",
00587                         7 => "/\[img\](.*?)\[\/img\]/s",
00588                         8 => "/\[size=(.+?)\](.+?)\[\/size\]/is",
00589                         9 => "/\[color\](.*?)\[\/color\]/s",
00590                         10 => "/\[size=(.+?)\](.+?)\[\/size\]/is",
00591                         11 => "/\[size\](.*?)\[\/size\]/s",
00592                         12 => "/\[code\](.*?)\[\/code\]/s",
00593                         13 => "/\[hr\]/s",
00594                         14 => "/\[s\](.*?)\[\/s\]/s",
00595                         15 => "/\[\[att\=(.*?)]](.*?)\[\[\/att]]/s",
00596                         16 => "/\[url=(.+?)\](.+?)\[\/url\]/is");
00597 
00598     $bbcode_replace = array(0 => "<strong>$1</strong>",
00599                             1 => "<em>$1</em>",
00600                             2 => "<u>$1</u>",
00601                             3 => "<blockquote><p>$1</p></blockquote>",
00602                             4 => "<blockquote cite=\"$1\"><p>$1 said:<br />$2</p></blockquote>",
00603                             5 => '<a href="$1" title="$1">$1</a>',
00604                             6 => "<a href=\"$1\" title=\"$1\">$2</a>",
00605                             7 => "<img src=\"$1\" alt=\"User submitted image\" />",
00606                             8 => "<span style=\"color:$1\">$2</span>",
00607                             9 => "<span style=\"color:red;\">$1</span>",
00608                             10 => "<span style=\"font-size:$1\">$2</span>",
00609                             11 => "<span style=\"font-size:large\">$1</span>",
00610                             12 => "<code>$1</code>",
00611                             13 => "<hr />",
00612                             14 => "<span style=\"text-decoration:line-through\">$1</span>",
00613                             15 => "<a href=\"{$CONFIG['application_webpath']}download.php?id=$1\">$2</a>",
00614                             16 => "<a href=\"$1\">$2</a>");
00615 
00616     $html = preg_replace($bbcode_regex, $bbcode_replace, $text);
00617     return $html;
00618 }
00619 
00620 
00627 function strip_bbcode_tooltip($text)
00628 {
00629     $bbcode_regex = array(0 => '/\[url\](.*?)\[\/url\]/s',
00630 
00631                         1 => '/\[url\=(.*?)\](.*?)\[\/url\]/s',
00632                         2 => '/\[color\=(.*?)\](.*?)\[\/color\]/s',
00633                         3 => '/\[size\=(.*?)\](.*?)\[\/size\]/s',
00634                         4 => '/\[blockquote\=(.*?)\](.*?)\[\/blockquote\]/s',
00635                         5 => '/\[blockquote\](.*?)\[\/blockquote\]/s',
00636                         6 => "/\[s\](.*?)\[\/s\]/s");
00637 
00638     $bbcode_replace = array(0 => '$1',
00639                             1 => '$2',
00640                             2 => '$2',
00641                             3 => '$2',
00642                             4 => '$2',
00643                             5 => '$1',
00644                             6 => '$1'
00645                             );
00646 
00647     return preg_replace($bbcode_regex, $bbcode_replace, $text);
00648 }
00649 
00650 
00657 function bbcode_toolbar($elementid)
00658 {
00659     $html = "\n<div class='bbcode_toolbar'>BBCode: ";
00660     $html .= "<a href=\"javascript:insertBBCode('{$elementid}', '[b]', '[/b]')\">B</a> ";
00661     $html .= "<a href=\"javascript:insertBBCode('{$elementid}', '[i]', '[/i]')\">I</a> ";
00662     $html .= "<a href=\"javascript:insertBBCode('{$elementid}', '[u]', '[/u]')\">U</a> ";
00663     $html .= "<a href=\"javascript:insertBBCode('{$elementid}', '[s]', '[/s]')\">S</a> ";
00664     $html .= "<a href=\"javascript:insertBBCode('{$elementid}', '[quote]', '[/quote]')\">Quote</a> ";
00665     $html .= "<a href=\"javascript:insertBBCode('{$elementid}', '[url]', '[/url]')\">Link</a> ";
00666     $html .= "<a href=\"javascript:insertBBCode('{$elementid}', '[img]', '[/img]')\">Img</a> ";
00667     $html .= "<a href=\"javascript:insertBBCode('{$elementid}', '[color]', '[/color]')\">Color</a> ";
00668     $html .= "<a href=\"javascript:insertBBCode('{$elementid}', '[size]', '[/size]')\">Size</a> ";
00669     $html .= "<a href=\"javascript:insertBBCode('{$elementid}', '[code]', '[/code]')\">Code</a> ";
00670     $html .= "<a href=\"javascript:insertBBCode('{$elementid}', '', '[hr]')\">HR</a> ";
00671     $html .= "</div>\n";
00672     return $html;
00673 }
00674 
00675 
00682 function new_note_form($linkid, $refid)
00683 {
00684     global $now, $sit, $iconset;
00685     $html = "<form name='addnote' action='note_new.php' method='post'>";
00686     $html .= "<div class='detailhead note'> <div class='detaildate'>".readable_date($now)."</div>\n";
00687     $html .= icon('note', 16, $GLOBALS['strNote']);
00688     $html .= " ".sprintf($GLOBALS['strNewNoteByX'], user_realname($sit[2]))."</div>\n";
00689     $html .= "<div class='detailentry note'>";
00690     $html .= "<textarea rows='3' cols='40' name='bodytext' style='width: 94%; margin-top: 5px; margin-bottom: 5px; margin-left: 3%; margin-right: 3%; background-color: transparent; border: 1px dashed #A2A86A;'></textarea>";
00691     if (!empty($linkid))
00692     {
00693         $html .= "<input type='hidden' name='link' value='{$linkid}' />";
00694     }
00695     else
00696     {
00697         $html .= "&nbsp;{$GLOBALS['strLInk']} <input type='text' name='link' size='3' />";
00698     }
00699 
00700     if (!empty($refid))
00701     {
00702         $html .= "<input type='hidden' name='refid' value='{$refid}' />";
00703     }
00704     else
00705     {
00706         $html .= "&nbsp;{$GLOBALS['strRefID']} <input type='text' name='refid' size='4' />";
00707     }
00708 
00709     $html .= "<input type='hidden' name='action' value='addnote' />";
00710     $html .= "<input type='hidden' name='rpath' value='{$_SERVER['PHP_SELF']}?{$_SERVER['QUERY_STRING']}' />";
00711     $html .= "<div style='text-align: right'><input type='submit' value='{$GLOBALS['strNewNote']}' /></div>\n";
00712     $html .= "</div>\n";
00713     $html .= "</form>";
00714     return $html;
00715 }
00716 
00717 
00725 function show_notes($linkid, $refid, $delete = TRUE)
00726 {
00727     global $sit, $iconset, $dbNotes, $strDelete, $strAreYouSureDelete;
00728     $sql = "SELECT * FROM `{$dbNotes}` WHERE link='{$linkid}' AND refid='{$refid}' ORDER BY timestamp DESC, id DESC";
00729     $result = mysql_query($sql);
00730     if (mysql_error()) trigger_error(mysql_error(), E_USER_WARNING);
00731     $countnotes = mysql_num_rows($result);
00732     if ($countnotes >= 1)
00733     {
00734         while ($note = mysql_fetch_object($result))
00735         {
00736             $html .= "<div class='detailhead note'> <div class='detaildate'>".readable_date(mysqlts2date($note->timestamp));
00737             if ($delete)
00738             {
00739                 $html .= "<a href='note_delete.php?id={$note->id}&amp;rpath=";
00740                 $html .= "{$_SERVER['PHP_SELF']}?{$_SERVER['QUERY_STRING']}' ";
00741                 if ($_SESSION['userconfig']['show_confirmation_delete'])
00742                 {
00743                     $html .= "onclick=\"return confirm_action('{$strAreYouSureDelete}', true);\"";
00744                 }
00745                 $html .= ">";
00746                 $html .= icon('delete', 16, $strDelete)."</a>";
00747             }
00748             $html .= "</div>\n"; // /detaildate
00749             $html .= icon('note', 16)." ";
00750             $html .= sprintf($GLOBALS['strNoteAddedBy'], user_realname($note->userid,TRUE));
00751             $html .= "</div>\n"; // detailhead
00752             $html .= "<div class='detailentry note'>";
00753             $html .= nl2br(bbcode($note->bodytext));
00754             $html .= "</div>\n";
00755         }
00756     }
00757     return $html;
00758 }
00759 
00760 
00778 function dashlet($dashboard, $dashletid, $icon, $title='', $link='', $content='')
00779 {
00780     global $strLoading;
00781     if (empty($icon)) $icon = icon('dashboard', 16);
00782     if (empty($title)) $title = $GLOBALS['strUntitled'];
00783     $displayfn = "dashboard_{$dashboard}_display";
00784     $editfn = "dashboard_{$dashboard}_edit";
00785 
00786     $html .= "<div class='windowbox' id='{$dashletid}'>";
00787     $html .= "<div class='windowtitle'>";
00788     $html .= "<div class='innerwindow'>";
00789     if (function_exists($displayfn))
00790     {
00791         $html .= "<a href=\"javascript:get_and_display('ajaxdata.php?action=dashboard_display&amp;dashboard={$dashboard}&amp;did={$dashletid}','win{$dashletid}',true);\">";
00792         $html .= icon('reload', 16, '', '', "refresh{$dashletid}")."</a>";
00793     }
00794 
00795     if (function_exists($editfn))
00796     {
00797         $html .= "<a href=\"javascript:get_and_display('ajaxdata.php?action=dashboard_edit&amp;dashboard={$dashboard}&amp;did={$dashletid}','win{$dashletid}',false);\">";
00798         $html .= icon('edit', 16)."</a>";
00799     }
00800     $html .= "</div>";
00801     if (!empty($link)) $html .= "<a href=\"{$link}\">{$icon}</a> <a href=\"{$link}\">{$title}</a>";
00802     else $html .= "{$icon} {$title}";
00803     $html .= "</div>\n";
00804     $html .= "<div class='window' id='win{$dashletid}'>";
00805     $html .= $content;
00806     $displayfn = "dashboard_{$dashboard}_display";
00807     if (function_exists($displayfn))
00808     {
00809         $html .= "<script type='text/javascript'>\n//<![CDATA[\nget_and_display('ajaxdata.php?action=dashboard_display&dashboard={$dashboard}','win{$dashletid}',true);\n//]]>\n</script>\n";
00810     }
00811     $html .= "</div></div>";
00812 
00813     return $html;
00814 }
00815 
00816 
00834 function dashlet_link($dashboard, $dashletid, $text='', $action='', $params='', $refresh = FALSE, $formid='')
00835 {
00836     if ($action == 'edit') $action = 'dashboard_edit';
00837     elseif ($action == 'save') $action = 'dashboard_save';
00838     else $action = 'dashboard_display';
00839     if (empty($text)) $text = $GLOBALS['strUntitled'];
00840 
00841     // Ensure the dashlet ID is always correct, 'win' gets prepended with each subpage
00842     // We only need it once
00843     $dashletid = 'win'.str_replace('win', '', $dashletid);
00844 
00845     // Convert refresh boolean to javascript text for boolean
00846     if ($refresh) $refresh = 'true';
00847     else $refresh = 'false';
00848 
00849     if ($action == 'dashboard_save' AND $formid == '') $formid = "{$dashboard}form";
00850 
00851     if ($action == 'dashboard_save') $html .= "<a href=\"javascript:ajax_save(";
00852     else  $html .= "<a href=\"javascript:get_and_display(";
00853     $html .= "'ajaxdata.php?action={$action}&dashboard={$dashboard}&did={$dashletid}";
00854     if (is_array($params))
00855     {
00856         foreach ($params AS $pname => $pvalue)
00857         {
00858             $html .= "&{$pname}={$pvalue}";
00859         }
00860     }
00861     //$html .= "&editaction=do_new&type={$type}";
00862 
00863     if ($action != 'dashboard_save')
00864     {
00865         $html .= "', '{$dashletid}'";
00866         $html .= ", $refresh";
00867     }
00868     else
00869     {
00870         $html .= "', '{$formid}'";
00871     }
00872     $html .= ");\">{$text}</a>";
00873 
00874     return $html;
00875 }
00876 
00877 
00885 function help_link($context)
00886 {
00887     global $strHelpChar;
00888     $html = "<span class='helplink'>[<a href='#' tabindex='-1' onmouseover=\"";
00889     $html .= "contexthelp(this, '$context'";
00890     if ($_SESSION['portalauth'] == TRUE) $html .= ",'portal'";
00891     else $html .= ",'standard'";
00892     $html .= ");return false;\">{$strHelpChar}<span>";
00893     $html .= "</span></a>]</span>";
00894 
00895     return $html;
00896 }
00897 
00898 
00906 function get_file_upload_error_message($errorcode, $name)
00907 {
00908     $str = "<div class='detailinfo'>\n";
00909 
00910     $str .=  sprintf($GLOBALS['strErrorOccuredUploadingX'], $_FILES['attachment']['name']);
00911 
00912     $str .=  "<p class='error'>";
00913     switch ($errorcode)
00914     {
00915         case UPLOAD_ERR_INI_SIZE:
00916         case UPLOAD_ERR_FORM_SIZE:
00917             $str .=  $GLOBALS['strAttachedFilesExceedMaxSize'];
00918             break;
00919         case UPLOAD_ERR_PARTIAL:
00920             $str .=  $GLOBALS['strFileOnlyPartiallyUploaded'];
00921             break;
00922         case UPLOAD_ERR_NO_FILE:
00923             $str .=  $GLOBALS['strnoFileUploaded'];
00924             break;
00925         case UPLOAD_ERR_NO_TMP_DIR:
00926             $str .=  $GLOBALS['strTemporaryFolderMissing'];
00927             break;
00928         default:
00929             $str .=  $GLOBALS['strAnUnknownErrorOccured'];
00930             break;
00931     }
00932     $str .=  "</p>";
00933     $str .=  "</div>";
00934 
00935     return $str;
00936 }
00937 
00938 
00947 function contract_details($id, $mode='internal')
00948 {
00949     global $CONFIG, $iconset, $dbMaintenance, $dbSites, $dbResellers, $dbLicenceTypes, $now;
00950 
00951     $sql  = "SELECT m.*, m.notes AS maintnotes, s.name AS sitename, ";
00952     $sql .= "r.name AS resellername, lt.name AS licensetypename ";
00953     $sql .= "FROM `{$dbMaintenance}` AS m, `{$dbSites}` AS s, ";
00954     $sql .= "`{$dbResellers}` AS r, `{$dbLicenceTypes}` AS lt ";
00955     $sql .= "WHERE s.id = m.site ";
00956     $sql .= "AND m.id='{$id}' ";
00957     $sql .= "AND m.reseller = r.id ";
00958     $sql .= "AND (m.licence_type IS NULL OR m.licence_type = lt.id) ";
00959     if ($mode == 'external') $sql .= "AND m.site = '{$_SESSION['siteid']}'";
00960 
00961     $maintresult = mysql_query($sql);
00962     if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_WARNING);
00963 
00964     $maint = mysql_fetch_object($maintresult);
00965 
00966     $html = "<table class='maintable vertical'>";
00967     $html .= "<tr><th>{$GLOBALS['strContract']} {$GLOBALS['strID']}:</th>";
00968     $html .= "<td><h3>".icon('contract', 32)." ";
00969     $html .= "{$maint->id}</h3></td></tr>";
00970     $html .= "<tr><th>{$GLOBALS['strStatus']}:</th><td>";
00971     if ($maint->term == 'yes')
00972     {
00973         $html .= "<strong>{$GLOBALS['strTerminated']}</strong>";
00974     }
00975     else
00976     {
00977         $html .= $GLOBALS['strActive'];
00978     }
00979 
00980     if ($maint->expirydate < $now AND $maint->expirydate != '-1')
00981     {
00982         $html .= ", <span class='expired'>{$GLOBALS['strExpired']}</span>";
00983     }
00984     $html .= "</td></tr>\n";
00985     $html .= "<tr><th>{$GLOBALS['strSite']}:</th>";
00986 
00987     if ($mode == 'internal')
00988     {
00989         $html .= "<td><a href=\"site_details.php?id=".$maint->site."\">".$maint->sitename."</a></td></tr>";
00990     }
00991     else
00992     {
00993         $html .= "<td><a href=\"sitedetails.php\">".$maint->sitename."</a></td></tr>";
00994     }
00995     $html .= "<tr><th>{$GLOBALS['strAdminContact']}:</th>";
00996 
00997     if ($mode == 'internal')
00998     {
00999         $html .= "<td><a href=\"contact_details.php?id=";
01000         $html .= "{$maint->admincontact}\">";
01001         $html .= contact_realname($maint->admincontact)."</a></td></tr>";
01002     }
01003     else
01004     {
01005         $html .= "<td><a href='contactdetails.php?id={$maint->admincontact}'>";
01006         $html .= contact_realname($maint->admincontact)."</a></td></tr>";
01007     }
01008 
01009     $html .= "<tr><th>{$GLOBALS['strReseller']}:</th><td>";
01010 
01011     if (empty($maint->resellername))
01012     {
01013         $html .= $GLOBALS['strNoReseller'];
01014     }
01015     else
01016     {
01017         $html .= $maint->resellername;
01018     }
01019     $html .= "</td></tr>";
01020     $html .= "<tr><th>{$GLOBALS['strProduct']}:</th><td>".product_name($maint->product)."</td></tr>";
01021     $html .= "<tr><th>{$GLOBALS['strIncidents']}:</th>";
01022     $html .= "<td>";
01023     $incidents_remaining = $maint->incident_quantity - $maint->incidents_used;
01024 
01025     if ($maint->incident_quantity == 0)
01026     {
01027         $quantity = $GLOBALS['strUnlimited'];
01028     }
01029     else
01030     {
01031         $quantity = $maint->incident_quantity;
01032     }
01033 
01034     $html .= sprintf($GLOBALS['strUsedNofN'], $maint->incidents_used, $quantity);
01035     if ($maint->incidents_used >= $maint->incident_quantity AND
01036         $maint->incident_quantity != 0)
01037     {
01038         $html .= " ({$GLOBALS['strZeroRemaining']})";
01039     }
01040 
01041     $html .= "</td></tr>";
01042     if ($maint->licence_quantity != '0')
01043     {
01044         $html .= "<tr><th>{$GLOBALS['strLicense']}:</th>";
01045         $html .= "<td>{$maint->licence_quantity} {$maint->licensetypename}</td></tr>\n";
01046     }
01047 
01048     $html .= "<tr><th>{$GLOBALS['strServiceLevel']}:</th><td>".get_sla_name($maint->servicelevel)."</td></tr>";
01049     $html .= "<tr><th>{$GLOBALS['strExpiryDate']}:</th><td>";
01050     if ($maint->expirydate == '-1')
01051     {
01052         $html .= "{$GLOBALS['strUnlimited']}";
01053     }
01054     else
01055     {
01056         $html .= ldate($CONFIG['dateformat_date'], $maint->expirydate);
01057     }
01058 
01059     $html .= "</td></tr>";
01060 
01061     if ($mode == 'internal')
01062     {
01063         $timed = servicelevel_timed($maint->servicelevel);
01064         $html .= "<tr><th>{$GLOBALS['strService']}</th><td>";
01065         $html .= contract_service_table($id, $timed);
01066         $html .= "</td></tr>\n";
01067 
01068         if ($timed)
01069         {
01070             $html .= "<tr><th>{$GLOBALS['strBalance']}</th><td>{$CONFIG['currency_symbol']}".number_format(get_contract_balance($id, TRUE, TRUE), 2);
01071             $multiplier = get_billable_multiplier(strtolower(date('D', $now)), date('G', $now));
01072             $html .= " (&cong;".contract_unit_balance($id, TRUE, TRUE)." units)";
01073             $html .= "</td></tr>";
01074         }
01075     }
01076 
01077     if ($maint->maintnotes != '' AND $mode == 'internal')
01078     {
01079         $html .= "<tr><th>{$GLOBALS['strNotes']}:</th><td>{$maint->maintnotes}</td></tr>";
01080     }
01081     $html .= "</table>";
01082 
01083     if ($mode == 'internal')
01084     {
01085         $operations = array();
01086         $operations[$GLOBALS['strEditContract']] = array('url' => "contract_edit.php?action=edit&amp;maintid=$id", 'perm' => PERM_CONTRACT_EDIT);
01087 
01088 
01089         if ($maint->term != 'yes')
01090         {
01091             $operations[$GLOBALS['strNewService']] = "contract_new_service.php?contractid={$id}";
01092         }
01093         $html .= "<p align='center'>".html_action_links($operations)."</p>";
01094     }
01095 
01096     $html .= "<h3>{$GLOBALS['strNamedContacts']}</h3>";
01097 
01098     if (mysql_num_rows($maintresult) > 0)
01099     {
01100         if ($maint->allcontactssupported == 'yes')
01101         {
01102             $html .= "<p class='info'>{$GLOBALS['strAllSiteContactsSupported']}</p>";
01103         }
01104         else
01105         {
01106             $allowedcontacts = $maint->supportedcontacts;
01107 
01108             $supportedcontacts = supported_contacts($id);
01109             $numberofcontacts = 0;
01110 
01111             $numberofcontacts = sizeof($supportedcontacts);
01112             if ($allowedcontacts == 0)
01113             {
01114                 $allowedcontacts = $GLOBALS['strUnlimited'];
01115             }
01116             $html .= "<table class='maintable'>";
01117             $supportcount = 1;
01118 
01119             if ($numberofcontacts > 0)
01120             {
01121                 foreach ($supportedcontacts AS $contact)
01122                 {
01123                     $html .= "<tr><th>{$GLOBALS['strContact']} #{$supportcount}:</th>";
01124                     $html .= "<td>".icon('contact', 16)." ";
01125                     if ($mode == 'internal')
01126                     {
01127                         $html .= "<a href=\"contact_details.php?";
01128                     }
01129                     else
01130                     {
01131                         $html .= "<a href=\"contactdetails.php?";
01132                     }
01133                     $html .= "id={$contact}\">".contact_realname($contact)."</a>, ";
01134                     $html .= contact_site($contact). "</td>";
01135 
01136                     if ($mode == 'internal')
01137                     {
01138                         $html .= "<td><a href=\"contract_delete_contact.php?contactid={$contact}&amp;maintid={$id}&amp;context=maintenance\">{$GLOBALS['strRemove']}</a></td></tr>\n";
01139                     }
01140                     else
01141                     {
01142                         $html .= "<td><a href=\"{$_SERVER['PHP_SELF']}?id={$id}&amp;contactid={$contact}&amp;action=remove\">{$GLOBALS['strRemove']}</a></td></tr>\n";
01143                     }
01144                     $supportcount++;
01145                 }
01146             }
01147             else
01148             {
01149                 $html .= "<tr><td>".user_alert($GLOBALS['strNoRecords'], E_USER_NOTICE)."</td></tr>";
01150             }
01151             $html .= "</table>";
01152         }
01153 
01154         if ($maint->allcontactssupported != 'yes')
01155         {
01156             $html .= "<p align='center'>";
01157             $html .= sprintf($GLOBALS['strUsedNofN'],
01158                             "<strong>".$numberofcontacts."</strong>",
01159                             "<strong>".$allowedcontacts."</strong>");
01160             $html .= "</p>";
01161 
01162             if ($numberofcontacts < $allowedcontacts OR $allowedcontacts == 0 AND $mode == 'internal')
01163             {
01164                 $html .= "<p align='center'><a href='contract_new_contact.php?maintid={$id}&amp;siteid={$maint->site}&amp;context=maintenance'>";
01165                 $html .= "{$GLOBALS['strNewNamedContact']}</a></p>";
01166             }
01167             else
01168             {
01169                 $html .= "<h3>{$GLOBALS['strNewNamedContact']}</h3>";
01170                 $html .= "<form action='{$_SERVER['PHP_SELF']}?id={$id}&amp;action=";
01171                 $html .= "add' method='post' >";
01172                 $html .= "<p align='center'>{$GLOBLAS['strNewSupportedContact']} ";
01173                 $html .= contact_site_drop_down('contactid',
01174                                                 'contactid',
01175                                                 maintenance_siteid($id),
01176                                                 supported_contacts($id));
01177                 $html .= help_link('NewSupportedContact');
01178                 $html .= " <input type='submit' value='{$GLOBALS['strNew']}' /></p></form>";
01179             }
01180             if ($mode == 'external')
01181             {
01182                 $html .= "<p align='center'><a href='newcontact.php'>";
01183                 $html .= "{$GLOBALS['strNewSiteContact']}</a></p>";
01184             }
01185         }
01186 
01187         $html .= "<br />";
01188         $html .= "<h3>{$GLOBALS['strSkillsSupportedUnderContract']}:</h3>";
01189         // supported software
01190         $sql = "SELECT * FROM `{$GLOBALS[dbSoftwareProducts]}` AS sp, `{$GLOBALS[dbSoftware]}` AS s ";
01191         $sql .= "WHERE sp.softwareid = s.id AND productid='{$maint->product}' ";
01192         $result = mysql_query($sql);
01193         if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_WARNING);
01194 
01195         if (mysql_num_rows($result)>0)
01196         {
01197             $html .="<table class='maintable'>";
01198             while ($software = mysql_fetch_object($result))
01199             {
01200                 $software->lifetime_end = mysql2date($software->lifetime_end);
01201                 $html .= "<tr><td> ".icon('skill', 16)." ";
01202                 if ($software->lifetime_end > 0 AND $software->lifetime_end < $now)
01203                 {
01204                     $html .= "<span class='deleted'>";
01205                 }
01206                 $html .= $software->name;
01207                 if ($software->lifetime_end > 0 AND $software->lifetime_end < $now)
01208                 {
01209                     $html .= "</span>";
01210                 }
01211                 $html .= "</td></tr>\n";
01212             }
01213             $html .= "</table>\n";
01214         }
01215         else
01216         {
01217             $html .= "<p align='center'>{$GLOBALS['strNone']} / {$GLOBALS['strUnknown']}<p>";
01218         }
01219     }
01220     else
01221     {
01222         $html = user_alert($GLOBALS['strNothingToDisplay'], E_USER_NOTICE);
01223     }
01224 
01225     return $html;
01226 }
01227 
01228 
01239 function group_user_selector($title, $level = 'engineer', $groupid = '', $type='radio')
01240 {
01241     global $dbUsers, $dbGroups;
01242 
01243     $str .= "<tr><th>{$title}</th>";
01244     $str .= "<td align='center'>";
01245 
01246     $sql = "SELECT DISTINCT(g.name), g.id FROM `{$dbUsers}` AS u, `{$dbGroups}` AS g ";
01247     $sql .= "WHERE u.status > 0 AND u.groupid = g.id ORDER BY g.name";
01248     $result = mysql_query($sql);
01249     if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_WARNING);
01250 
01251     if (mysql_num_rows($result) > 0)
01252     {
01253         while ($row = mysql_fetch_object($result))
01254         {
01255             if ($type == 'radio')
01256             {
01257                 $str .= "<input type='radio' name='group' id='{$row->name}' onclick='groupMemberSelect(\"{$row->name}\", \"TRUE\")' ";
01258             }
01259             elseif ($type == 'checkbox')
01260             {
01261                 $str .= "<input type='checkbox' name='{$row->name}' id='{$row->name}' onclick='groupMemberSelect(\"{$row->name}\", \"FALSE\")' ";
01262             }
01263 
01264             if ($groupid == $row->id)
01265             {
01266                 $str .= " checked='checked' ";
01267                 $groupname = $row->name;
01268             }
01269 
01270             $str .= "/>{$row->name} \n";
01271         }
01272 
01273         $str .="<br />";
01274 
01275 
01276         $sql = "SELECT u.id, u.realname, g.name FROM `{$dbUsers}` AS u, `{$dbGroups}` AS g ";
01277         $sql .= "WHERE u.status > 0 AND u.groupid = g.id ORDER BY username";
01278         $result = mysql_query($sql);
01279         if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_ERROR);
01280 
01281         if ($level == "management")
01282         {
01283             $str .= "<select name='users[]' id='include' multiple='multiple' size='20'>\n";
01284         }
01285         elseif ($level == "engineer")
01286         {
01287             $str .= "<select name='users[]' id='include' multiple='multiple' size='20' style='display:none'>\n";
01288         }
01289 
01290         while ($row = mysql_fetch_object($result))
01291         {
01292             $str .= "<option value='{$row->id}' ";
01293             if ($row->name == $groupname) $str .= "selected='selected' ";
01294             $str .= ">{$row->realname} ({$row->name})</option>\n";
01295         }
01296         $str .= "</select>\n";
01297         $str .= "<br />";
01298         if ($level == "engineer")
01299         {
01300             $visibility = " style='display:none'";
01301         }
01302 
01303         $str .= "<input type='button' id='selectall' onclick='doSelect(true, \"include\")' value='Select All' {$visibility} />";
01304         $str .= "<input type='button' id='clearselection' onclick='doSelect(false, \"include\")' value='Clear Selection' {$visibility} />";
01305     }
01306     else
01307     {
01308         echo $strNoneAvailable;
01309     }
01310 
01311     $str .= "</td>";
01312     $str .= "</tr>\n";
01313 
01314     return $str;
01315 }
01316 
01317 
01326 function emoticons($text)
01327 {
01328     global $CONFIG;
01329 
01330     $html = '';
01331     if ($_SESSION['userconfig']['show_emoticons'] == 'TRUE')
01332     {
01333         $smiley_url = "{$CONFIG['application_uriprefix']}{$CONFIG['application_webpath']}images/emoticons/";
01334         $smiley_regex = array(0 => "/\:[-]?\)/s",
01335                             1 => "/\:[-]?\(/s",
01336                             2 => "/\;[-]?\)/s",
01337                             3 => "/\:[-]?[pP]/s",
01338                             4 => "/\:[-]?@/s",
01339                             5 => "/\:[-]?[Oo]/s",
01340                             6 => "/\:[-]?\\$/s",
01341                             7 => "/\\([Yy]\)/s",
01342                             8 => "/\\([Nn]\)/s",
01343                             9 => "/\\([Bb]\)/s",
01344                             10 => "/\:[-]?[dD]/s"
01345                             );
01346 
01347         $smiley_replace = array(0 => "<img src='{$smiley_url}smile.png' alt='$1' title='$1' />",
01348                                 1 => "<img src='{$smiley_url}sad.png' alt='$1' title='$1' />",
01349                                 2 => "<img src='{$smiley_url}wink.png' alt='$1' title='$1' />",
01350                                 3 => "<img src='{$smiley_url}tongue.png' alt='$1' title='$1' />",
01351                                 4 => "<img src='{$smiley_url}angry.png' alt='$1' title='$1' />",
01352                                 5 => "<img src='{$smiley_url}omg.png' alt='$1' title='$1' />",
01353                                 6 => "<img src='{$smiley_url}embarassed.png' alt='$1' title='$1' />",
01354                                 7 => "<img src='{$smiley_url}thumbs_up.png' alt='$1' title='$1' />",
01355                                 8 => "<img src='{$smiley_url}thumbs_down.png' alt='$1' title='$1' />",
01356                                 9 => "<img src='{$smiley_url}beer.png' alt='$1' title='$1' />",
01357                                 10 => "<img src='{$smiley_url}teeth.png' alt='$1' title='$1' />"
01358                                 );
01359 
01360         $html = preg_replace($smiley_regex, $smiley_replace, $text);
01361     }
01362     else
01363     {
01364         $html = $text;
01365     }
01366 
01367     return $html;
01368 }
01369 
01370 
01378 function alpha_index($baseurl = '#', $displayinactive = FALSE)
01379 {
01380     global $i18nAlphabet, $strAll;
01381 
01382     if ($displayinactive === TRUE OR $displayinactive === 'true')
01383     {
01384         $inactivestring="displayinactive=true";
01385     }
01386     else
01387     {
01388         $inactivestring="displayinactive=false";
01389     }
01390 
01391     $html = '';
01392     if (!empty($i18nAlphabet))
01393     {
01394         $html .= "<span class='separator'> | </span>";
01395         $len = mb_strlen($i18nAlphabet);
01396         for ($i = 0; $i < $len; $i++)
01397         {
01398             $html .= "<a href=\"{$baseurl}";
01399             $html .= urlencode(mb_substr($i18nAlphabet, $i, 1))."\">";
01400             $html .= mb_substr($i18nAlphabet, $i, 1)."</a><span class='separator'> | </span> \n";
01401         }
01402         $html .= "<a href='{$_SERVER['PHP_SELF']}?search_string=*&amp;{$inactivestring}'>{$strAll}</a>\n";
01403     }
01404     return $html;
01405 }
01406 
01407 
01412 function password_reveal_link($id)
01413 {
01414     $html = "<a href=\"javascript:password_reveal('$id')\" id=\"link{$id}\">{$GLOBALS['strReveal']}</a>";
01415     return $html;
01416 }
01417 
01418 
01425 function qtype_listbox($type)
01426 {
01427     global $CONFIG, $strRating, $strOptions, $strMultipleOptions, $strText;
01428 
01429     $html .= "<select name='type'>\n";
01430     $html .= "<option value='rating'";
01431     if ($type == 'rating') $html .= " selected='selected'";
01432     $html .= ">{$strRating}</option>";
01433 
01434     $html .= "<option value='options'";
01435     if ($type == 'options') $html .= " selected='selected'";
01436     $html .= ">{$strOptions}</option>";
01437 
01438     $html .= "<option value='multioptions'";
01439     if ($type == 'multioptions') $html .= " selected='selected'";
01440     $html .= ">{$strMultipleOptions}</option>";
01441 
01442     $html .= "<option value='text'";
01443     if ($type == 'text') $html .= " selected='selected'";
01444     $html .= ">{$strText}</option>";
01445 
01446     $html .= "</select>\n";
01447 
01448     return $html;
01449 }
01450 
01451 
01459 function feedback_qtype_listbox($type)
01460 {
01461     global $CONFIG, $strRating, $strOptions, $strMultipleOptions, $strText;
01462 
01463     $html .= "<select name='type'>\n";
01464     $html .= "<option value='rating'";
01465     if ($type == 'rating') $html .= " selected='selected'";
01466     $html .= ">{$strRating}</option>";
01467 
01468     $html .= "<option value='options'";
01469     if ($type == 'options') $html .= " selected='selected'";
01470     $html .= ">{$strOptions}</option>";
01471 
01472     $html .= "<option value='multioptions'";
01473     if ($type == 'multioptions') $html .= " selected='selected'";
01474     $html .= ">{$strMultipleOptions}</option>";
01475 
01476     $html .= "<option value='text'";
01477     if ($type == 'text') $html .= " selected='selected'";
01478     $html .= ">{$strText}</option>";
01479 
01480     $html .= "</select>\n";
01481 
01482     return $html;
01483 }
01484 
01485 
01486 
01487 
01488 
01493 function show_links($origtab, $colref, $level=0, $parentlinktype='', $direction='lr')
01494 {
01495     global $dbLinkTypes, $dbLinks;
01496     // Maximum recursion
01497     $maxrecursions = 15;
01498 
01499     if ($level <= $maxrecursions)
01500     {
01501         $sql = "SELECT * FROM `{$dbLinkTypes}` WHERE origtab='$origtab' ";
01502         if (!empty($parentlinktype)) $sql .= "AND id='{$parentlinktype}'";
01503         $result = mysql_query($sql);
01504         if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING);
01505         while ($linktype = mysql_fetch_object($result))
01506         {
01507             // Look up links of this type
01508             $lsql = "SELECT * FROM `{$dbLinks}` WHERE linktype='{$linktype->id}' ";
01509             if ($direction == 'lr') $lsql .= "AND origcolref='{$colref}'";
01510             elseif ($direction == 'rl') $lsql .= "AND linkcolref='{$colref}'";
01511             $lresult = mysql_query($lsql);
01512             if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING);
01513             if (mysql_num_rows($lresult) >= 1)
01514             {
01515                 if (mysql_num_rows($lresult) >= 1)
01516                 {
01517                     $html .= "<ul>";
01518                     $html .= "<li>";
01519                     while ($link = mysql_fetch_object($lresult))
01520                     {
01521                         $recsql = "SELECT {$linktype->selectionsql} AS recordname FROM {$linktype->linktab} WHERE ";
01522                         if ($direction == 'lr') $recsql .= "{$linktype->linkcol}='{$link->linkcolref}' ";
01523                         elseif ($direction == 'rl') $recsql .= "{$linktype->origcol}='{$link->origcolref}' ";
01524                         $recresult = mysql_query($recsql);
01525                         if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING);
01526                         while ($record = mysql_fetch_object($recresult))
01527                         {
01528                             if ($link->direction == 'bi')
01529                             {
01530                                 $html .= "<strong>{$linktype->name}</strong> ";
01531                             }
01532                             elseif ($direction == 'lr')
01533                             {
01534                                 $html .= "<strong>{$linktype->lrname}</strong> ";
01535                             }
01536                             elseif ($direction == 'rl')
01537                             {
01538                                 $html .= "<strong>{$linktype->rlname}</strong> ";
01539                             }
01540                             else
01541                             {
01542                                 $html = $GLOBALS['strError'];
01543                             }
01544 
01545                             if ($direction == 'lr')
01546                             {
01547                                 $currentlinkref = $link->linkcolref;
01548                             }
01549                             elseif ($direction == 'rl')
01550                             {
01551                                 $currentlinkref = $link->origcolref;
01552                             }
01553 
01554                             $viewurl = str_replace('%id%',$currentlinkref,$linktype->viewurl);
01555 
01556                             $html .= "{$currentlinkref}: ";
01557                             if (!empty($viewurl)) $html .= "<a href='$viewurl'>";
01558                             $html .= "{$record->recordname}";
01559                             if (!empty($viewurl)) $html .= "</a>";
01560                             $html .= " - ".user_realname($link->userid,TRUE);
01561                             $html .= show_links($linktype->linktab, $currentlinkref, $level+1, $linktype->id, $direction); // Recurse
01562                             $html .= "</li>\n";
01563                         }
01564                     }
01565                     $html .= "</ul>\n";
01566                 }
01567                 else
01568                 {
01569                     $html .= "<p>{$GLOBALS['strNone']}</p>";
01570                 }
01571             }
01572         }
01573     }
01574     else
01575     {
01576         $html .= "<p class='error'>{$GLOBALS['strError']}: Maximum number of {$maxrecursions} recursions reached</p>";
01577     }
01578     return $html;
01579 }
01580 
01581 
01586 function show_create_links($table, $ref)
01587 {
01588     global $dbLinkTypes;
01589     $html .= "<p align='center'>{$GLOBALS['strNewLink']}: ";
01590     $sql = "SELECT * FROM `{$dbLinkTypes}` WHERE origtab='$table' OR linktab='$table' ";
01591     $result = mysql_query($sql);
01592     if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING);
01593     $numlinktypes = mysql_num_rows($result);
01594     $rowcount = 1;
01595     while ($linktype = mysql_fetch_object($result))
01596     {
01597         if ($linktype->origtab == $table AND $linktype->linktab != $table)
01598         {
01599             $html .= "<a href='link_new.php?origtab=tasks&amp;origref={$ref}&amp;linktype={$linktype->id}'>{$linktype->lrname}</a>";
01600         }
01601         elseif ($linktype->origtab != $table AND $linktype->linktab == $table)
01602         {
01603             $html .= "<a href='link_new.php?origtab=tasks&amp;origref={$ref}&amp;linktype={$linktype->id}'>{$linktype->rlname}</a>";
01604         }
01605         else
01606         {
01607             $html .= "<a href='link_new.php?origtab=tasks&amp;origref={$ref}&amp;linktype={$linktype->id}'>{$linktype->lrname}</a> | ";
01608             $html .= "<a href='link_new.php?origtab=tasks&amp;origref={$ref}&amp;linktype={$linktype->id}&amp;dir=rl'>{$linktype->rlname}</a>";
01609         }
01610 
01611         if ($rowcount < $numlinktypes) $html .= " | ";
01612         $rowcount++;
01613     }
01614     $html .= "</p>";
01615     return $html;
01616 }
01617 
01618 
01627 function show_edit_site($site, $mode='internal')
01628 {
01629     global $CONFIG, $strRequired;
01630     $sql = "SELECT * FROM `{$GLOBALS['dbSites']}` WHERE id='$site' ";
01631     $siteresult = mysql_query($sql);
01632     if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_WARNING);
01633     echo show_form_errors('site_edit');
01634     clear_form_errors('site_edit');
01635     while ($obj = mysql_fetch_object($siteresult))
01636     {
01637         if ($mode == 'internal')
01638         {
01639             $html .= "<h2>".icon('site', 32)." {$GLOBALS['strEditSite']}: {$site} - ";
01640             $html .= site_name($site)."</h2>";
01641             plugin_do('site_edit');
01642         }
01643         else
01644         {
01645             $html .= "<h2>".icon('site', 32)." ".site_name($site)."</h2>";
01646         }
01647 
01648         $html .= "<form name='edit_site' action='{$_SERVER['PHP_SELF']}";
01649         $html .= "?action=update' method='post' onsubmit='return ";
01650         $html .= "confirm_action(\"{$GLOBALS['strAreYouSureMakeTheseChanges']}\")'>";
01651         $html .= "<table class='maintable vertical'>";
01652         $html .= "<tr><th>{$GLOBALS['strName']}:</th>";
01653         $html .= "<td><input class='required' maxlength='50' name='name' size='40' value='{$obj->name}' />";
01654         $html .= " <span class='required'>{$GLOBALS['strRequired']}</span></td></tr>\n";
01655         if ($mode == 'internal')
01656         {
01657             $html .= "<tr><th>{$GLOBALS['strTags']}:</th><td><textarea rows='2' cols='60' name='tags'>";
01658             $html .= list_tags($site, TAG_SITE, false)."</textarea>\n";
01659         }
01660         $html .= "<tr><th>{$GLOBALS['strDepartment']}:</th>";
01661         $html .= "<td><input maxlength='50' name='department' size='40' value='{$obj->department}' />";
01662         $html .= "</td></tr>\n";
01663         $html .= "<tr><th>{$GLOBALS['strAddress1']}:</th>";
01664         $html .= "<td><input maxlength='50' name='address1' class='required' ";
01665         $html .= "size='40' value='{$obj->address1}' /> <span class='required'>{$strRequired}</span>";
01666         $html .= "</td></tr>\n";
01667         $html .= "<tr><th>{$GLOBALS['strAddress2']}: </th><td><input maxlength='50' name='address2' size='40' value='{$obj->address2}' /></td></tr>\n";
01668         $html .= "<tr><th>{$GLOBALS['strCity']}:</th><td><input maxlength='255' name='city' size='40' value='{$obj->city}' /></td></tr>\n";
01669         $html .= "<tr><th>{$GLOBALS['strCounty']}:</th><td><input maxlength='255' name='county' size='40' value='{$obj->county}' /></td></tr>\n";
01670         $html .= "<tr><th>{$GLOBALS['strPostcode']}:</th><td><input maxlength='255' name='postcode' size='40' value='{$obj->postcode}' /></td></tr>\n";
01671         $html .= "<tr><th>{$GLOBALS['strCountry']}:</th><td>".country_drop_down('country', $obj->country)."</td></tr>\n";
01672         $html .= "<tr><th>{$GLOBALS['strTelephone']}:</th><td>";
01673         $html .= "<input maxlength='255' name='telephone' size='40' value='{$obj->telephone}' />";
01674         $html .= "</td></tr>\n";
01675         $html .= "<tr><th>{$GLOBALS['strFax']}:</th><td>";
01676         $html .= "<input maxlength='255' name='fax' size='40' value='{$obj->fax}' /></td></tr>\n";
01677         $html .= "<tr><th>{$GLOBALS['strEmail']}:</th><td>";
01678         $html .= "<input maxlength='255' name='email' size='40' value='{$obj->email}' />";
01679         $html .= "</td></tr>\n";
01680         $html .= "<tr><th>{$GLOBALS['strWebsite']}:</th><td>";
01681         $html .= "<input maxlength='255' name='websiteurl' size='40' value='{$obj->websiteurl}' /></td></tr>\n";
01682         $html .= "<tr><th>{$GLOBALS['strSiteType']}:</th><td>\n";
01683         $html .= sitetype_drop_down('typeid', $obj->typeid);
01684         $html .= "</td></tr>\n";
01685         if ($mode == 'internal')
01686         {
01687             $html .= "<tr><th>{$GLOBALS['strSalesperson']}:</th><td>";
01688             $html .= user_drop_down('owner', $obj->owner, $accepting = FALSE, '', '', TRUE);
01689             $html .= "</td></tr>\n";
01690         }
01691 
01692         if ($mode == 'internal')
01693         {
01694             $html .= "<tr><th>{$GLOBALS['strIncidentPool']}:</th>";
01695             $incident_pools = explode(',', "{$GLOBALS['strNone']},{$CONFIG['incident_pools']}");
01696             if (array_key_exists($obj->freesupport, $incident_pools) == FALSE)
01697             {
01698                 array_unshift($incident_pools, $obj->freesupport);
01699             }
01700             $html .= "<td>".array_drop_down($incident_pools,'incident_pool',$obj->freesupport)."</td></tr>";
01701             $html .= "<tr><th>{$GLOBALS['strActive']}:</th><td><input type='checkbox' name='active' ";
01702             if ($obj->active == 'true')
01703             {
01704                 $html .= "checked='{$obj->active}'";
01705             }
01706             $html .= " value='true' /></td></tr>\n";
01707             $html .= "<tr><th>{$GLOBALS['strNotes']}:</th><td>";
01708             $html .= "<textarea rows='5' cols='30' name='notes'>{$obj->notes}</textarea>";
01709             $html .= "</td></tr>\n";
01710             plugin_do('site_edit_form');
01711         }
01712         $html .= "</table>\n";
01713         $html .= "<input name='site' type='hidden' value='$site' />";
01714         $html .= "<p class='formbuttons'><input name='reset' type='reset' value='{$GLOBALS['strReset']}' /> ";
01715         $html .= "<input name='submit' type='submit' value='{$GLOBALS['strSave']}' /></p>";
01716         if ($mode == 'internal')
01717         {
01718             $html .= "<p><a href=\"site_details.php?id={$site}\">{$GLOBALS['strReturnWithoutSaving']}</a></p>";
01719         }
01720         $html .= "</form>";
01721     }
01722     return $html;
01723 }
01724 
01725 
01734 function show_new_contact($siteid = 0, $mode = 'internal')
01735 {
01736     global $CONFIG;
01737     $returnpage = cleanvar($_REQUEST['return']);
01738     if (!empty($_REQUEST['name']))
01739     {
01740         $name = explode(' ',cleanvar(urldecode($_REQUEST['name'])), 2);
01741         $_SESSION['formdata']['new_contact']['forenames'] = ucfirst($name[0]);
01742         $_SESSION['formdata']['new_contact']['surname'] = ucfirst($name[1]);
01743     }
01744 
01745     $html = show_form_errors('new_contact');
01746     clear_form_errors('new_contact');
01747     $html .= "<h2>".icon('contact', 32)." ";
01748     if ($mode == 'external')
01749     {
01750         $html .= "{$GLOBALS['strNewSiteContact']}";
01751     }
01752     else
01753     {
01754         $html .= "{$GLOBALS['strNewContact']}";
01755     }
01756     $html .= "</h2>";
01757 
01758     if ($mode == 'internal')
01759     {
01760         plugin_do('contact_new');
01761         $html .= "<h5 class='warning'>{$GLOBALS['strAvoidDupes']}</h5>";
01762     }
01763     $html .= "<form name='contactform' action='{$_SERVER['PHP_SELF']}' ";
01764     $html .= "method='post' onsubmit=\"return confirm_action('{$GLOBALS['strAreYouSureAdd']}')\">";
01765     $html .= "<table class='maintable vertical'>";
01766     $html .= "<tr><th>{$GLOBALS['strName']}</th>\n";
01767 
01768     $html .= "<td>";
01769     $html .= "\n<table><tr><td align='center'>{$GLOBALS['strTitle']}<br />";
01770     $html .= "<input maxlength='50' name='courtesytitle' title=\"";
01771     $html .= "{$GLOBALS['strCourtesyTitle']}\" size='7'";
01772     if ($_SESSION['formdata']['new_contact']['courtesytitle'] != '')
01773     {
01774         $html .= "value='{$_SESSION['formdata']['new_contact']['courtesytitle']}'";
01775     }
01776     $html .= "/></td>\n";
01777 
01778     $html .= "<td align='center'>{$GLOBALS['strForenames']}<br />";
01779     $html .= "<input class='required' maxlength='100' name='forenames' ";
01780     $html .= "size='15' title=\"{$GLOBALS['strForenames']}\"";
01781     if ($_SESSION['formdata']['new_contact']['forenames'] != '')
01782     {
01783         $html .= "value='{$_SESSION['formdata']['new_contact']['forenames']}'";
01784     }
01785     $html .= "/></td>\n";
01786 
01787     $html .= "<td align='center'>{$GLOBALS['strSurname']}<br />";
01788     $html .= "<input class='required' maxlength='100' name='surname' ";
01789     $html .= "size='20' title=\"{$GLOBALS['strSurname']}\"";
01790     if ($_SESSION['formdata']['new_contact']['surname'] != '')
01791     {
01792         $html .= "value='{$_SESSION['formdata']['new_contact']['surname']}'";
01793     }
01794     $html .= " /> <span class='required'>{$GLOBALS['strRequired']}</span></td></tr>\n";
01795     $html .= "</table>\n</td></tr>\n";
01796 
01797     $html .= "<tr><th>{$GLOBALS['strJobTitle']}</th><td><input maxlength='255'";
01798     $html .= " name='jobtitle' size='35' title=\"{$GLOBALS['strJobTitle']}\"";
01799     if ($_SESSION['formdata']['new_contact']['jobtitle'] != '')
01800     {
01801         $html .= "value='{$_SESSION['formdata']['new_contact']['jobtitle']}'";
01802     }
01803     $html .= " /></td></tr>\n";
01804     if ($mode == 'internal')
01805     {
01806         $html .= "<tr><th>{$GLOBALS['strSite']}</th><td>";
01807         $html .= site_drop_down('siteid',$siteid, TRUE)."<span class='required'>{$GLOBALS['strRequired']}</span></td></tr>\n";
01808     }
01809     else
01810     {
01811         // For external always force the site to be the session site
01812         $html .= "<input type='hidden' name='siteid' value='{$_SESSION['siteid']}' />";
01813     }
01814 
01815     $html .= "<tr><th>{$GLOBALS['strDepartment']}</th><td><input maxlength='255' name='department' size='35'";
01816     if ($_SESSION['formdata']['new_contact']['department'] != '')
01817     {
01818         $html .= "value='{$_SESSION['formdata']['new_contact']['department']}'";
01819     }
01820     $html .= "/></td></tr>\n";
01821 
01822     $html .= "<tr><th>{$GLOBALS['strEmail']}</th><td>";
01823     $html .= "<input class='required' maxlength='100' name='email' size='35'";
01824     if ($_SESSION['formdata']['new_contact']['email'])
01825     {
01826         $html .= "value='{$_SESSION['formdata']['new_contact']['email']}'";
01827     }
01828     $html .= "/> <span class='required'>{$GLOBALS['strRequired']}</span> ";
01829 
01830     $html .= "<label>";
01831     $html .= html_checkbox('dataprotection_email', 'No');
01832     $html .= "{$GLOBALS['strEmail']} {$GLOBALS['strDataProtection']}</label>".help_link("EmailDataProtection");
01833     $html .= "</td></tr>\n";
01834 
01835     $html .= "<tr><th>{$GLOBALS['strTelephone']}</th><td><input maxlength='50' name='phone' size='35'";
01836     if ($_SESSION['formdata']['new_contact']['phone'] != '')
01837     {
01838         $html .= "value='{$_SESSION['formdata']['new_contact']['phone']}'";
01839     }
01840     $html .= "/> ";
01841 
01842     $html .= "<label>";
01843     $html .= html_checkbox('dataprotection_phone', 'No');
01844     $html .= "{$GLOBALS['strTelephone']} {$GLOBALS['strDataProtection']}</label>".help_link("TelephoneDataProtection");
01845     $html .= "</td></tr>\n";
01846 
01847     $html .= "<tr><th>{$GLOBALS['strMobile']}</th><td><input maxlength='100' name='mobile' size='35'";
01848     if ($_SESSION['formdata']['new_contact']['mobile'] != '')
01849     {
01850         $html .= "value='{$_SESSION['formdata']['new_contact']['mobile']}'";
01851     }
01852     $html .= "/></td></tr>\n";
01853 
01854     $html .= "<tr><th>{$GLOBALS['strFax']}</th><td><input maxlength='50' name='fax' size='35'";
01855     if ($_SESSION['formdata']['new_contact']['fax'])
01856     {
01857         $html .= "value='{$_SESSION['formdata']['new_contact']['fax']}'";
01858     }
01859     $html .= "/></td></tr>\n";
01860 
01861     $html .= "<tr><th>{$GLOBALS['strAddress']}</th><td><label>";
01862     $html .= html_checkbox('dataprotection_address', 'No');
01863     $html .= " {$GLOBALS['strAddress']} {$GLOBALS['strDataProtection']}</label>";
01864     $html .= help_link("AddressDataProtection")."</td></tr>\n";
01865     $html .= "<tr><th></th><td><label><input type='checkbox' name='usesiteaddress' value='yes' onclick=\"$('hidden').toggle();\" /> {$GLOBALS['strSpecifyAddress']}</label></td></tr>\n";
01866     $html .= "<tbody id='hidden' style='display:none'>";
01867     $html .= "<tr><th>{$GLOBALS['strAddress1']}</th>";
01868     $html .= "<td><input maxlength='255' name='address1' size='35' /></td></tr>\n";
01869     $html .= "<tr><th>{$GLOBALS['strAddress2']}</th>";
01870     $html .= "<td><input maxlength='255' name='address2' size='35' /></td></tr>\n";
01871     $html .= "<tr><th>{$GLOBALS['strCity']}</th><td><input maxlength='255' name='city' size='35' /></td></tr>\n";
01872     $html .= "<tr><th>{$GLOBALS['strCounty']}</th><td><input maxlength='255' name='county' size='35' /></td></tr>\n";
01873     $html .= "<tr><th>{$GLOBALS['strCountry']}</th><td>";
01874     $html .= country_drop_down('country', $CONFIG['home_country'])."</td></tr>\n";
01875     $html .= "<tr><th>{$GLOBALS['strPostcode']}</th><td><input maxlength='255' name='postcode' size='35' /></td></tr>\n";
01876     $html .= "</tbody>";
01877     if ($mode == 'internal')
01878     {
01879         $html .= "<tr><th>{$GLOBALS['strNotes']}</th><td><textarea cols='60' rows='5' name='notes'>";
01880         if ($_SESSION['formdata']['new_contact']['notes'] != '')
01881         {
01882             $html .= $_SESSION['formdata']['new_contact']['notes'];
01883         }
01884         $html .= "</textarea></td></tr>\n";
01885     }
01886     $html .= "<tr><th>{$GLOBALS['strEmailDetails']}</th>";
01887     // Check the box to send portal details, only if portal is enabled
01888     $html .= "<td><input type='checkbox' id='emaildetails' name='emaildetails' value='on'";
01889     if ($CONFIG['portal'] == TRUE) $html .= " checked='checked'";
01890     else $html .= " disabled='disabled'";
01891     $html .= " />";
01892     $html .= "<label for='emaildetails'>{$GLOBALS['strEmailContactLoginDetails']}</label></td></tr>";
01893     plugin_do('contact_new_form');
01894     $html .= "</table>\n\n";
01895     if (!empty($returnpage)) $html .= "<input type='hidden' name='return' value='{$returnpage}' />";
01896     $html .= "<p class='formbuttons'><input name='reset' type='reset' value='{$GLOBALS['strReset']}' /> ";
01897     $html .= "<input name='submit' type='submit' value=\"{$GLOBALS['strSave']}\" /></p>";
01898     $html .= "</form>\n";
01899 
01900     //cleanup form vars
01901     clear_form_data('new_contact');
01902 
01903     return $html;
01904 }
01905 
01906 
01914 function format_external_id($externalid, $escalationpath='')
01915 {
01916     global $CONFIG, $dbEscalationPaths;
01917 
01918     if (!empty($escalationpath))
01919     {
01920         // Extract escalation path
01921         $epsql = "SELECT id, name, track_url, home_url, url_title FROM `{$dbEscalationPaths}` ";
01922         if (!empty($escalationpath)) $epsql .= "WHERE id='$escalationpath' ";
01923         $epresult = mysql_query($epsql);
01924         if (mysql_error()) trigger_error(mysql_error(), E_USER_WARNING);
01925         if (mysql_num_rows($epresult) >= 1)
01926         {
01927             while ($escalationpath = mysql_fetch_object($epresult))
01928             {
01929                 $epath['name'] = $escalationpath->name;
01930                 $epath['track_url'] = $escalationpath->track_url;
01931                 $epath['home_url'] = $escalationpath->home_url;
01932                 $epath['url_title'] = $escalationpath->url_title;
01933             }
01934 
01935             if (!empty($externalid))
01936             {
01937                 $epathurl = str_replace('%externalid%', $externalid, $epath['track_url']);
01938                 $html = "<a href='{$epathurl}' title='{$epath['url_title']}'>{$externalid}</a>";
01939             }
01940             else
01941             {
01942                 $epathurl = $epath['home_url'];
01943                 $html = "<a href='{$epathurl}' title='{$epath['url_title']}'>{$epath['name']}</a>";
01944             }
01945         }
01946     }
01947     else
01948     {
01949         $html = $externalid;
01950     }
01951     return $html;
01952 }
01953 
01954 
01962 function contracts_for_contacts_table($userid, $mode = 'internal')
01963 {
01964     global $now, $CONFIG, $sit;
01965     if ((!empty($sit[2]) AND user_permission($sit[2], PERM_SUPPORTED_PRODUCT_VIEW)
01966         OR ($_SESSION['usertype'] == 'admin'))) // view supported products
01967     {
01968         $html .= "<h4>".icon('contract', 16)." {$GLOBALS['strContracts']}:</h4>";
01969         // Contracts we're explicit supported contact for
01970         $sql  = "SELECT sc.maintenanceid AS maintenanceid, m.product, p.name AS productname, ";
01971         $sql .= "m.expirydate, m.term ";
01972         $sql .= "FROM `{$GLOBALS['dbContacts']}` AS c, ";
01973         $sql .= "`{$GLOBALS['dbSupportContacts']}` AS sc, ";
01974         $sql .= "`{$GLOBALS['dbMaintenance']}` AS m, ";
01975         $sql .= "`{$GLOBALS['dbProducts']}` AS p ";
01976         $sql .= "WHERE c.id = '{$userid}' ";
01977         $sql .= "AND (sc.maintenanceid=m.id AND sc.contactid='{$userid}') ";
01978         $sql .= "AND m.product=p.id  ";
01979         // Contracts we're an 'all supported' on
01980         $sql .= "UNION ";
01981         $sql .= "SELECT m.id AS maintenanceid, m.product, p.name AS productname, ";
01982         $sql .= "m.expirydate, m.term ";
01983         $sql .= "FROM `{$GLOBALS['dbContacts']}` AS c, ";
01984         $sql .= "`{$GLOBALS['dbMaintenance']}` AS m, ";
01985         $sql .= "`{$GLOBALS['dbProducts']}` AS p ";
01986         $sql .= "WHERE c.id = '{$userid}' AND c.siteid = m.site ";
01987         $sql .= "AND m.allcontactssupported = 'yes' ";
01988         $sql .= "AND m.product=p.id  ";
01989 
01990         $result = mysql_query($sql);
01991         if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_WARNING);
01992         if (mysql_num_rows($result) > 0)
01993         {
01994             $html .= "<table class='maintable'>";
01995             $html .= "<tr>";
01996             $html .= "<th>{$GLOBALS['strID']}</th><th>{$GLOBALS['strProduct']}</th><th>{$GLOBALS['strExpiryDate']}</th>";
01997             $html .= "</tr>\n";
01998 
01999             $supportcount = 1;
02000             $shade = 'shade2';
02001             while ($obj = mysql_fetch_object($result))
02002             {
02003                 if ($obj->term == 'yes')
02004                 {
02005                     $shade = 'expired';
02006                 }
02007 
02008                 if ($obj->expirydate < $now AND $obj->expirydate != -1)
02009                 {
02010                     $shade = 'expired';
02011                 }
02012 
02013                 $html .= "<tr><td class='{$shade}'>";
02014                 $html .= ''.icon('contract', 16)." ";
02015                 if ($mode == 'internal')
02016                 {
02017                     $html .= "<a href='contract_details.php?id=";
02018                 }
02019                 else
02020                 {
02021                     $html .= "<a href='contracts.php?id=";
02022                 }
02023                 $html .= "{$obj->maintenanceid}'>";
02024                 $html .= "{$GLOBALS['strContract']}: ";
02025                 $html .= "{$obj->maintenanceid}</a></td>";
02026                 $html .= "<td class='{$shade}'>{$obj->productname}</td>";
02027                 $html .= "<td class='{$shade}'>";
02028                 if ($obj->expirydate == -1)
02029                 {
02030                     $html .= $GLOBALS['strUnlimited'];
02031                 }
02032                 else
02033                 {
02034                     $html .= ldate($CONFIG['dateformat_date'], $obj->expirydate);
02035                 }
02036                 if ($obj->term == 'yes')
02037                 {
02038                     $html .= " {$GLOBALS['strTerminated']}";
02039                 }
02040 
02041                 $html .= "</td>";
02042                 $html .= "</tr>\n";
02043                 $supportcount++;
02044                 if ($shade == 'shade1') $shade = 'shade2';
02045                 else $shade = 'shade1';
02046             }
02047             $html .= "</table>\n";
02048         }
02049         else
02050         {
02051             $html .= "<p align='center'>{$GLOBALS['strNone']}</p>\n";
02052         }
02053 
02054         if ($mode == 'internal')
02055         {
02056             $html .= "<p align='center'>";
02057             $html .= "<a href='contract_new_contact.php?contactid={$userid}&amp;context=contact'>";
02058             $html .= "{$GLOBALS['strAssociateContactWithContract']}</a></p>\n";
02059         }
02060     }
02061 
02062     return $html;
02063 }
02064 
02065 
02072 function time_picker($hour = '', $minute = '', $name_prefix = '')
02073 {
02074     global $CONFIG;
02075 
02076     // FIXME TODO use $CONFIG['dateformat_shorttime']
02077 
02078     $m = 0;
02079 
02080     if (empty($hour))
02081     {
02082         $hour = floor($CONFIG['start_working_day'] / 3600);
02083         $m = ($CONFIG['start_working_day'] % 3600) / 60;
02084     }
02085 
02086     if (empty($minute))
02087     {
02088         $minute = $m;
02089     }
02090 
02091     $html = "<select id='{$name_prefix}time_picker_hour' name='{$name_prefix}time_picker_hour'>\n";
02092     for ($i = 0; $i < 24; $i++)
02093     {
02094         $html .= "<option value='{$i}'";
02095         if ($i == $hour) $html .= " selected='selected'";
02096         $html .= ">".str_pad($i, 2, '0', STR_PAD_LEFT)."</option>\n";
02097     }
02098     $html .= "</select>\n";
02099 
02100     $html .= ":";
02101 
02102     $html .= "<select id='{$name_prefix}time_picker_minute' name='{$name_prefix}time_picker_minute'>\n";
02103     for ($i = 0; $i < 60; $i += $CONFIG['display_minute_interval'])
02104     {
02105         $html .= "<option value='{$i}'";
02106         if ($i == $minute) $html .= " selected='selected'";
02107         $html .= ">".str_pad($i, 2, '0', STR_PAD_LEFT)."</option>\n";
02108     }
02109     $html .= "</select>\n";
02110 
02111     return $html;
02112 }
02113 
02114 
02123 function html_incident_popup_link($incidentid, $linktext, $tooltip = NULL)
02124 {
02125     if ($_SESSION['userconfig']['incident_popup_onewindow'] == 'FALSE')
02126     {
02127         $windowname = "incident{$incidentid}";
02128     }
02129     else
02130     {
02131         $windowname = "sit_popup";
02132     }
02133     $html = "<a href=\"javascript:incident_details_window('{$incidentid}','{$windowname}')\"";
02134     if (!empty($tooltip))
02135     {
02136         $html .= "class='info'";
02137     }
02138     $html .= ">{$linktext}";
02139     if (!empty($tooltip))
02140     {
02141         $html .= "<span>{$tooltip}</span>";
02142     }
02143     $html .= "</a>";
02144 
02145     return $html;
02146 }
02147 
02148 
02155 function html_status_row($statusentry)
02156 {
02157     $html = "<tr><td>";
02158     switch ($statusentry->status)
02159     {
02160         case INSTALL_OK:
02161             $html .= icon('solution', 16, $GLOBALS['strSuccess']);
02162             break;
02163         case INSTALL_WARN:
02164             $html .= icon('warning', 16, $GLOBALS['strWarning']);
02165             break;
02166         case INSTALL_FATAL:
02167             $html .= icon('error', 16, $GLOBALS['strError']);
02168             break;
02169         case INSTALL_INFO:
02170             $html .= icon('info', 16, $GLOBALS['strInfo']);
02171     }
02172 
02173     $html .= "</td><td>{$statusentry->checkname}</td><td>{$statusentry->minimum}</td><td>{$statusentry->found}</td>";
02174 
02175     $html .= "</tr>";
02176     return $html;
02177 }
02178 
02179 
02188 function html_check_extension($extension, $text, $min_status)
02189 {
02190     if (extension_loaded($extension))
02191     {
02192         $str = $GLOBALS['strInstalled'];
02193         $toreturn = INSTALL_OK;
02194     }
02195     else
02196     {
02197         $str = $GLOBALS['strNotInstalled'];
02198         $toreturn = $min_status;
02199     }
02200     echo html_status_row($toreturn, $text, $GLOBALS['strInstalled'], $str);
02201 
02202     return $toreturn;
02203 }
02204 
02205 
02212 function html_install_status($status)
02213 {
02214     $html = "<table class='maintable'><tr><th></th><th>{$GLOBALS['strRequirement']}</th><th>{$GLOBALS['strRequired']}</th><th>{$GLOBALS['strActual']}</th></tr>";
02215 
02216     foreach ($status->statusentries AS $entry)
02217     {
02218         $html .= html_status_row($entry);
02219     }
02220 
02221     $html .= "</table>";
02222 
02223     return $html;
02224 }
02225 
02226 
02235 function html_action_links(&$actions)
02236 {
02237     $access = TRUE;
02238     $html .= "<span class='actionlinks'>";
02239     $actionscount = count($actions);
02240     $count = 1;
02241     foreach ($actions AS $label => $action)
02242     {
02243         if (is_array($action))
02244         {
02245             $url = $action['url'];
02246             if (!user_permission($_SESSION['userid'], $action['perm']))
02247             {
02248                 $url = "{$CONFIG['application_webpath']}noaccess.php?id={$action['perm']}";
02249                 $access = FALSE;
02250             }
02251         }
02252         else
02253         {
02254             $url = $action;
02255             $access = TRUE;
02256         }
02257         $html .= "<a href=\"{$url}\"";
02258         if (!$access)
02259         {
02260             $html .= " class='greyed' title=\"{$GLOBALS['strNoPermission']}\"";
02261         }
02262         $html .= ">{$label}</a>";
02263         $count++;
02264         if ($count <= $actionscount)
02265         {
02266             $html .= "<span class='separator'> | </span>";
02267         }
02268     }
02269     $html .= "</span>";
02270     unset($actions);
02271     return $html;
02272 }
02273 
02274 
02281 function html_hmenu($hmenu)
02282 {
02283     global $CONFIG;
02284     $html = "<div id='menu'>\n";
02285     $html .= "<ul id='menuList'>\n";
02286     foreach ($hmenu[0] as $top => $topvalue)
02287     {
02288         if ((!empty($topvalue['enablevar']) AND $CONFIG[$topvalue['enablevar']] !== FALSE
02289             AND $CONFIG[$topvalue['enablevar']] !== 'disabled')
02290             OR empty($topvalue['enablevar']))
02291         {
02292             $html .= "<li class='menuitem'>";
02293             // Permission Required: ".permission_name($topvalue['perm'])."
02294             if ($topvalue['perm'] > 0 AND !in_array($topvalue['perm'], $_SESSION['permissions']))
02295             {
02296                 $html .= "<a href='javascript:void(0);' class='greyed'>{$topvalue['name']}</a>";
02297             }
02298             else
02299             {
02300                 $html .= "<a href='{$topvalue['url']}'>{$topvalue['name']}</a>";
02301             }
02302 
02303             if ($topvalue['submenu'] > 0 AND ($topvalue['perm'] == '' OR in_array($topvalue['perm'], $_SESSION['permissions'])))
02304             {
02305                 $html .= "\n<ul>"; //  id='menuSub'
02306                 foreach ($hmenu[$topvalue['submenu']] as $sub => $subvalue)
02307                 {
02308                     if ((!empty($subvalue['enablevar']) AND $CONFIG[$subvalue['enablevar']] == TRUE
02309                         AND $CONFIG[$subvalue['enablevar']] !== 'disabled')
02310                         OR empty($subvalue['enablevar']))
02311                     {
02312                         if (array_key_exists('submenu', $subvalue) AND $subvalue['submenu'] > 0)
02313                         {
02314                             $html .= "<li class='submenu'>";
02315                         }
02316                         else
02317                         {
02318                             $html .= "<li>";
02319                         }
02320 
02321                         if ($subvalue['perm'] > 0 AND !in_array($subvalue['perm'], $_SESSION['permissions']))
02322                         {
02323                             $html .= "<a href='javascript:void(0);' class='greyed'>{$subvalue['name']}</a>";
02324                         }
02325                         else
02326                         {
02327                             $html .= "<a href=\"{$subvalue['url']}\">{$subvalue['name']}</a>";
02328                         }
02329 
02330                         if (array_key_exists('submenu', $subvalue) AND $subvalue['submenu'] > 0 AND in_array($subvalue['perm'], $_SESSION['permissions']))
02331                         {
02332                             $html .= "<ul>"; // id ='menuSubSub'
02333                             foreach ($hmenu[$subvalue['submenu']] as $subsub => $subsubvalue)
02334                             {
02335                                 if ((!empty($subsubvalue['enablevar']) AND $CONFIG[$subsubvalue['enablevar']] == TRUE
02336                                     AND $CONFIG[$subsubvalue['enablevar']] !== 'disabled')
02337                                     OR empty($subsubvalue['enablevar']))
02338                                 {
02339                                     if (array_key_exists('submenu', $subsubvalue) AND $subsubvalue['submenu'] > 0)
02340                                     {
02341                                         $html .= "<li class='submenu'>";
02342                                     }
02343                                     else
02344                                     {
02345                                         $html .= "<li>";
02346                                     }
02347 
02348                                     if ($subsubvalue['perm'] >=1 AND !in_array($subsubvalue['perm'], $_SESSION['permissions']))
02349                                     {
02350                                         $html .= "<a href=\"javascript:void(0);\" class='greyed'>{$subsubvalue['name']}</a>";
02351                                     }
02352                                     else
02353                                     {
02354                                         $html .= "<a href='{$subsubvalue['url']}'>{$subsubvalue['name']}</a>";
02355                                     }
02356 
02357                                     if (array_key_exists('submenu', $subsubvalue) AND $subsubvalue['submenu'] > 0 AND in_array($subsubvalue['perm'], $_SESSION['permissions']))
02358                                     {
02359                                         $html .= "<ul>"; // id ='menuSubSubSub'
02360                                         foreach ($hmenu[$subsubvalue['submenu']] as $subsubsub => $subsubsubvalue)
02361                                         {
02362                                              if ((!empty($subsubsubvalue['enablevar']) AND $CONFIG[$subsubsubvalue['enablevar']])
02363                                                 OR empty($subsubsubvalue['enablevar']))
02364                                             {
02365                                                 if ($subsubsubvalue['submenu'] > 0)
02366                                                 {
02367                                                     $html .= "<li class='submenu'>";
02368                                                 }
02369                                                 else
02370                                                 {
02371                                                     $html .= "<li>";
02372                                                 }
02373 
02374                                                 if ($subsubsubvalue['perm'] >=1 AND !in_array($subsubsubvalue['perm'], $_SESSION['permissions']))
02375                                                 {
02376                                                     $html .= "<a href='javascript:void(0);' class='greyed'>{$subsubsubvalue['name']}</a>";
02377                                                 }
02378                                                 else
02379                                                 {
02380                                                     $html .= "<a href='{$subsubsubvalue['url']}'>{$subsubsubvalue['name']}</a>";
02381                                                 }
02382                                                 $html .= "</li>\n";
02383                                             }
02384                                         }
02385                                         $html .= "</ul>\n";
02386                                     }
02387                                     $html .= "</li>\n";
02388                                 }
02389                             }
02390                             $html .= "</ul>\n";
02391                         }
02392                         $html .= "</li>\n";
02393                     }
02394                 }
02395                $html .= "</ul>\n";
02396             }
02397             $html .= "</li>\n";
02398         }
02399     }
02400     $html .= "</ul>\n\n";
02401     $html .= "</div>\n";
02402 
02403     return $html;
02404 }
02405 
02406 
02413 function map_link($address)
02414 {
02415     $url = str_replace('{address}', urlencode($address), $GLOBALS['CONFIG']['map_url']);
02416     $link = "<span class='maplink'><a target='_blank' href=\"{$url}\">{$GLOBALS['strMap']}</a></span>";
02417 
02418     return $link;
02419 }
02420 
02421 
02429 function html_plugin_contexts($plugin)
02430 {
02431     global $PLUGINACTIONS, $strNone;
02432     $html = '';
02433 
02434     if (is_array($PLUGINACTIONS))
02435     {
02436         foreach ($PLUGINACTIONS AS $key => $value)
02437         {
02438             foreach($value AS $hook)
02439             {
02440                 if (beginsWith($hook, $plugin))
02441                 {
02442                     $phook = str_replace($plugin . '_' , '', $hook);
02443                     if (!function_exists($hook))
02444                     {
02445                         $phook = "☠ {$hook}";
02446                         $key = "<span style='text-decoration: line-through;'>{$key}</span>";
02447                     }
02448                     $html .= "<strong title=\"{$phook}()\" style=\"cursor:help;\">{$key}</strong> &nbsp; ";
02449                 }
02450             }
02451         }
02452     }
02453     else
02454     {
02455         $html = $strNone;
02456     }
02457 
02458     return $html;
02459 }
02460 
02461 ?>