3 * FusionForge miscellaneous utils
5 * Copyright 1999-2001, VA Linux Systems, Inc.
6 * Copyright 2009, Roland Mas
8 * This file is part of FusionForge.
10 * FusionForge is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published
12 * by the Free Software Foundation; either version 2 of the License,
13 * or (at your option) any later version.
15 * FusionForge is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with FusionForge; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
27 * is_utf8($string) - utf-8 detection
29 * From http://www.php.net/manual/en/function.mb-detect-encoding.php#85294
31 function is_utf8($str) {
35 for($i=0; $i<$len; $i++){
38 if(($c >= 254)) return false;
39 elseif($c >= 252) $bits=6;
40 elseif($c >= 248) $bits=5;
41 elseif($c >= 240) $bits=4;
42 elseif($c >= 224) $bits=3;
43 elseif($c >= 192) $bits=2;
45 if(($i+$bits) > $len) return false;
49 if($b < 128 || $b > 191) return false;
58 * removeCRLF() - remove any Carriage Return-Line Feed from a string.
59 * That function is useful to remove the possibility of a CRLF Injection when sending mail
60 * All the data that we will send should be passed through that function
62 * @param string The string that we want to empty from any CRLF
64 function util_remove_CRLF($str) {
65 return strtr($str, "\015\012", ' ');
70 * util_check_fileupload() - determines if a filename is appropriate for upload
72 * @param array The uploaded file as returned by getUploadedFile()
74 function util_check_fileupload($filename) {
76 /* Empty file is a valid file.
77 This is because this function should be called
78 unconditionally at the top of submit action processing
79 and many forms have optional file upload. */
80 if ($filename == 'none' || $filename == '') {
84 /* This should be enough... */
85 if (!is_uploaded_file($filename)) {
88 /* ... but we'd rather be paranoic */
89 if (strstr($filename, '..')) {
92 if (!is_file($filename)) {
95 if (!file_exists($filename)) {
98 if ((dirname($filename) != '/tmp') &&
99 (dirname($filename) != "/var/tmp")) {
106 * util_send_message() - Send email
107 * This function should be used in place of the PHP mail() function
109 * @param string The email recipients address
110 * @param string The email subject
111 * @param string The body of the email message
112 * @param string The optional email sender address. Defaults to 'noreply@'
113 * @param string The addresses to blind-carbon-copy this message
114 * @param string The optional email sender name. Defaults to ''
115 * @param boolean Whether to send plain text or html email
118 function util_send_message($to,$subject,$body,$from='',$BCC='',$sendername='',$extra_headers='',$send_html_email=false) {
119 global $sys_bcc_all_email_address,$sys_sendmail_path;
122 $to='noreply@'.$GLOBALS['sys_default_domain'];
125 $from='noreply@'.$GLOBALS['sys_default_domain'];
129 $charset = _('UTF-8');
135 if ($extra_headers) {
136 $body2 .= $extra_headers."\n";
139 "\nFrom: ".util_encode_mailaddr($from,$sendername,$charset);
140 if (!empty($sys_bcc_all_email_address)) {
141 $BCC.=",$sys_bcc_all_email_address";
144 $body2 .= "\nBCC: $BCC";
146 $send_html_email?$type="html":$type="plain";
147 $body2 .= "\n".util_encode_mimeheader("Subject", $subject, $charset).
148 "\nContent-type: text/$type; charset=$charset".
150 util_convert_body($body, $charset);
152 if (!$sys_sendmail_path){
153 $sys_sendmail_path="/usr/sbin/sendmail";
156 $handle = popen($sys_sendmail_path." -f'$from' -t -i", 'w');
157 fwrite ($handle, $body2);
162 * util_encode_mailaddr() - Encode email address to MIME format
164 * @param string The email address
165 * @param string The email's owner name
166 * @param string The converting charset
169 function util_encode_mailaddr($email,$name,$charset) {
170 if (function_exists('mb_convert_encoding') && trim($name) != "") {
171 $name = "=?".$charset."?B?".
172 base64_encode(mb_convert_encoding(
173 $name,$charset,"UTF-8")).
177 return $name." <".$email."> ";
181 * util_encode_mimeheader() - Encode mimeheader
183 * @param string The name of the header (e.g. "Subject")
184 * @param string The email subject
185 * @param string The converting charset (like ISO-2022-JP)
186 * @return string The MIME encoded subject
189 function util_encode_mimeheader($headername,$str,$charset) {
190 if (function_exists('mb_internal_encoding') &&
191 function_exists('mb_encode_mimeheader')) {
192 $x = mb_internal_encoding();
193 mb_internal_encoding("UTF-8");
194 $y = mb_encode_mimeheader($headername . ": " . $str,
196 mb_internal_encoding($x);
200 if (!function_exists('mb_convert_encoding')) {
201 return $headername . ": " . $str;
204 return $headername . ": " . "=?".$charset."?B?".
205 base64_encode(mb_convert_encoding(
206 $str,$charset,"UTF-8")).
211 * util_convert_body() - Convert body of the email message
213 * @param string The body of the email message
214 * @param string The charset of the email message
215 * @return string The converted body of the email message
218 function util_convert_body($str,$charset) {
219 if (!function_exists('mb_convert_encoding') || $charset == 'UTF-8') {
223 return mb_convert_encoding($str,$charset,"UTF-8");
226 function util_send_jabber($to,$subject,$body) {
227 if (!$GLOBALS['sys_use_jabber']) {
230 $JABBER = new Jabber();
231 if (!$JABBER->Connect()) {
232 echo '<br />Unable to connect';
235 //$JABBER->SendAuth();
236 //$JABBER->AccountRegistration();
237 if (!$JABBER->SendAuth()) {
238 echo '<br />Auth Failure';
239 $JABBER->Disconnect();
241 //or die("Couldn't authenticate!");
243 $JABBER->SendPresence(NULL, NULL, "online");
245 $body=htmlspecialchars($body);
246 $to_arr=explode(',',$to);
247 for ($i=0; $i<count($to_arr); $i++) {
249 //echo '<br />Sending Jabbers To: '.$to_arr[$i];
250 if (!$JABBER->SendMessage($to_arr[$i], "normal", NULL, array("body" => $body,"subject"=>$subject))) {
251 echo '<br />Error Sending to '.$to_arr[$i];
256 $JABBER->CruiseControl(2);
257 $JABBER->Disconnect();
261 * util_prep_string_for_sendmail() - Prepares a string to be sent by email
263 * @param string The text to be prepared
264 * @returns The prepared text
267 function util_prep_string_for_sendmail($body) {
268 /*$body=str_replace("`","\\`",$body);
269 $body=str_replace("\"","\\\"",$body);
270 $body=str_replace("\$","\\\$",$body);*/
271 $body = escapeshellarg($body);
276 * util_handle_message() - a convenience wrapper which sends messages
277 * to either a jabber account or email account or both, depending on
280 * @param array array of user_id's from the user table
281 * @param string subject of the message
282 * @param string the message body
283 * @param string a comma-separated list of email address
284 * @param string a comma-separated list of jabber address
285 * @param string From header
287 function util_handle_message($id_arr,$subject,$body,$extra_emails='',$extra_jabbers='',$from='') {
290 if (count($id_arr) < 1) {
293 $res = db_query_params ('SELECT user_id,jabber_address,email,jabber_only FROM users WHERE user_id = ANY ($1)',
294 array (db_int_array_to_any_clause ($id_arr))) ;
295 $rows = db_numrows($res) ;
297 for ($i=0; $i<$rows; $i++) {
298 if (db_result($res, $i, 'user_id') == 100) {
299 // Do not send messages to "Nobody"
303 // Build arrays of the jabber address
305 if (db_result($res,$i,'jabber_address')) {
306 $address['jabber_address'][]=db_result($res,$i,'jabber_address');
307 if (db_result($res,$i,'jabber_only') != 1) {
308 $address['email'][]=db_result($res,$i,'email');
311 $address['email'][]=db_result($res,$i,'email');
314 if (isset ($address['email']) && count($address['email']) > 0) {
315 $extra_emails=implode($address['email'],',').',' . $extra_emails;
317 if (isset ($address['jabber_address']) && count($address['jabber_address']) > 0) {
318 $extra_jabbers=implode($address['jabber_address'],',').','.$extra_jabbers;
322 util_send_message('',$subject,$body,$from,$extra_emails);
324 if ($extra_jabbers) {
325 util_send_jabber($extra_jabbers,$subject,$body);
330 * util_unconvert_htmlspecialchars() - Unconverts a string converted with htmlspecialchars()
331 * This function requires PHP 4.0.3 or greater
333 * @param string The string to unconvert
334 * @returns The unconverted string
337 function util_unconvert_htmlspecialchars($string) {
338 if (strlen($string) < 1) {
341 //$trans = get_html_translation_table(HTMLENTITIES, ENT_QUOTES);
342 $trans = get_html_translation_table(HTML_ENTITIES);
343 $trans = array_flip ($trans);
344 $str = strtr ($string, $trans);
350 * util_result_columns_to_assoc() - Takes a result set and turns the column pair into an associative array
352 * @param string The result set ID
353 * @param int The column key
354 * @param int The optional column value
355 * @returns An associative array
358 function util_result_columns_to_assoc($result, $col_key=0, $col_val=1) {
359 $rows=db_numrows($result);
363 for ($i=0; $i<$rows; $i++) {
364 $arr[db_result($result,$i,$col_key)]=db_result($result,$i,$col_val);
373 * util_result_column_to_array() - Takes a result set and turns the optional column into an array
375 * @param int The result set ID
376 * @param int The column
380 function &util_result_column_to_array($result, $col=0) {
382 Takes a result set and turns the optional column into
385 $rows=db_numrows($result);
389 for ($i=0; $i<$rows; $i++) {
390 $arr[$i]=db_result($result,$i,$col);
399 * util_wrap_find_space() - Find the first space in a string
401 * @param string The string in which to find the space (must be UTF8!)
402 * @param int The number of characters to wrap - Default is 80
403 * @returns The position of the first space
406 function util_wrap_find_space($string,$wrap) {
413 //find the first space starting at $start
414 $pos=@strpos($string,' ',$start);
416 //if that space is too far over, go back and start more to the left
417 if (($pos > ($wrap+5)) || !$pos) {
419 $start=($wrap-($try*5));
420 //if we've gotten so far left , just truncate the line
423 $code = ord(substr($string,$wrap,1));
426 //Here is single byte character
427 //or head of multi byte character
430 //Do not break multi byte character
445 * util_line_wrap() - Automatically linewrap text
447 * @param string The text to wrap
448 * @param int The number of characters to wrap - Default is 80
449 * @param string The line break to use - Default is '\n'
450 * @returns The wrapped text
453 function util_line_wrap ($text, $wrap = 80, $break = "\n") {
454 $paras = explode("\n", $text);
458 while ($i < count($paras)) {
459 if (strlen($paras[$i]) <= $wrap) {
460 $result[] = $paras[$i];
463 $pos=util_wrap_find_space($paras[$i],$wrap);
465 $result[] = substr($paras[$i], 0, $pos);
467 $new = trim(substr($paras[$i], $pos, strlen($paras[$i]) - $pos));
470 $pos=util_wrap_find_space($paras[$i],$wrap);
476 return implode($break, $result);
480 * util_make_links() - Turn URL's into HREF's.
482 * @param string The URL
483 * @returns The HREF'ed URL
486 function util_make_links ($data='') {
490 $lines = split("\n",$data);
492 while ( list ($key,$line) = each ($lines)) {
493 // When we come here, we usually have form input
494 // encoded in entities. Our aim is to NOT include
495 // angle brackets in the URL
496 // (RFC2396; http://www.w3.org/Addressing/URL/5.1_Wrappers.html)
497 $line = str_replace('>', "\1", $line);
498 $line = eregi_replace("([ \t]|^)www\."," http://www.",$line);
499 $text = eregi_replace("([[:alnum:]]+)://([^[:space:]<\1]*)([[:alnum:]#?/&=])", "<a href=\"\\1://\\2\\3\" target=\"_new\">\\1://\\2\\3</a>", $line);
500 $text = eregi_replace("([[:space:]]|^)(([a-z0-9_]|\\-|\\.)+@([^[:space:]]*)([[:alnum:]-]))", "\\1<a href=\"mailto:\\2\" target=\"_new\">\\2</a>", $text);
501 $text = str_replace("\1", '>', $text);
508 * show_priority_colors_key() - Show the priority colors legend
511 function show_priority_colors_key() {
512 echo '<p /><strong> '._('Priority Colors').':</strong><br />
514 <table border="0"><tr>';
516 for ($i=1; $i<6; $i++) {
518 <td class="priority'.$i.'">'.$i.'</td>';
520 echo '</tr></table>';
524 * utils_buildcheckboxarray() - Build a checkbox array
526 * @param int Number of options to be in the array
527 * @param string The name of the checkboxes
528 * @param array An array of boxes to be pre-checked
531 function utils_buildcheckboxarray($options,$name,$checked_array) {
532 $option_count=count($options);
533 $checked_count=count($checked_array);
535 for ($i=1; $i<=$option_count; $i++) {
537 <br /><input type="checkbox" name="'.$name.'" value="'.$i.'"';
538 for ($j=0; $j<$checked_count; $j++) {
539 if ($i == $checked_array[$j]) {
543 echo '> '.$options[$i];
548 * utils_requiredField() - Adds the required field marker
550 * @return a string holding the HTML to mark a required field
552 function utils_requiredField() {
553 return '<span class="requiredfield">*</span>';
557 * GraphResult() - Takes a database result set and builds a graph.
558 * The first column should be the name, and the second column should be the values
559 * Be sure to include HTL_Graphs.php before using this function
561 * @author Tim Perdue tperdue@valinux.com
562 * @param int The databse result set ID
563 * @param string The title of the graph
566 Function GraphResult($result,$title) {
567 $rows=db_numrows($result);
569 if ((!$result) || ($rows < 1)) {
575 for ($j=0; $j<db_numrows($result); $j++) {
576 if (db_result($result, $j, 0) != '' && db_result($result, $j, 1) != '' ) {
577 $names[$j]= db_result($result, $j, 0);
578 $values[$j]= db_result($result, $j, 1);
583 This is another function detailed below
585 GraphIt($names,$values,$title);
590 * GraphIt() - Build a graph
592 * @author Tim Perdue tperdue@valinux.com
593 * @param array An array of names
594 * @param array An array of values
595 * @param string The title of the graph
598 Function GraphIt($name_string,$value_string,$title) {
601 $counter=count($name_string);
604 Can choose any color you wish
608 for ($i = 0; $i < $counter; $i++) {
609 $bars[$i]=$HTML->COLOR_LTBACK1;
612 $counter=count($value_string);
615 Figure the max_value passed in, so scale can be determined
620 for ($i = 0; $i < $counter; $i++) {
621 if ($value_string[$i] > $max_value) {
622 $max_value=$value_string[$i];
626 if ($max_value < 1) {
631 I want my graphs all to be 800 pixels wide, so that is my divisor
634 $scale=(400/$max_value);
637 I create a wrapper table around the graph that holds the title
643 echo $GLOBALS['HTML']->listTableTop ($title_arr);
646 Create an associate array to pass in. I leave most of it blank
675 This is the actual call to the HTML_Graphs class
678 html_graph($name_string,$value_string,$bars,$vals);
682 <!-- end outer graph table -->';
683 echo $GLOBALS['HTML']->listTableBottom();
687 * ShowResultSet() - Show a generic result set
688 * Very simple, plain way to show a generic result set
690 * @param int The result set ID
691 * @param string The title of the result set
692 * @param bool The option to turn URL's into links
693 * @param bool The option to display headers
694 * @param array The db field name -> label mapping
695 * @param array Don't display these cols
698 function ShowResultSet($result,$title='',$linkify=false,$displayHeaders=true,$headerMapping=array(), $excludedCols=array()) {
699 global $group_id,$HTML;
702 $rows = db_numrows($result);
703 $cols = db_numfields($result);
705 echo '<table border="0" width="100%">';
707 /* Create the headers */
708 $headersCellData = array();
709 $colsToKeep = array();
710 for ($i=0; $i < $cols; $i++) {
711 $fieldName = db_fieldname($result, $i);
712 if(in_array($fieldName, $excludedCols)) {
716 if(isset($headerMapping[$fieldName])) {
717 if(is_array($headerMapping[$fieldName])) {
718 $headersCellData[] = $headerMapping[$fieldName];
720 $headersCellData[] = array($headerMapping[$fieldName]);
724 $headersCellData[] = array($fieldName);
728 /* Create the title */
729 if(strlen($title) > 0) {
730 $titleCellData = array();
731 $titleCellData[] = array($title, 'colspan="'.count($headersCellData).'"');
732 echo $HTML->multiTableRow('', $titleCellData, TRUE);
735 /* Display the headers */
736 if($displayHeaders) {
737 echo $HTML->multiTableRow('', $headersCellData, TRUE);
740 /* Create the rows */
741 for ($j = 0; $j < $rows; $j++) {
742 echo '<tr '. $HTML->boxGetAltRowStyle($j) . '>';
743 for ($i = 0; $i < $cols; $i++) {
744 if(in_array($i, $colsToKeep)) {
745 if ($linkify && $i == 0) {
746 $link = '<a href="'.getStringFromServer('PHP_SELF').'?';
748 if ($linkify == "bug_cat") {
749 $link .= 'group_id='.$group_id.'&bug_cat_mod=y&bug_cat_id='.db_result($result, $j, 'bug_category_id').'">';
750 } else if($linkify == "bug_group") {
751 $link .= 'group_id='.$group_id.'&bug_group_mod=y&bug_group_id='.db_result($result, $j, 'bug_group_id').'">';
752 } else if($linkify == "patch_cat") {
753 $link .= 'group_id='.$group_id.'&patch_cat_mod=y&patch_cat_id='.db_result($result, $j, 'patch_category_id').'">';
754 } else if($linkify == "support_cat") {
755 $link .= 'group_id='.$group_id.'&support_cat_mod=y&support_cat_id='.db_result($result, $j, 'support_category_id').'">';
756 } else if($linkify == "pm_project") {
757 $link .= 'group_id='.$group_id.'&project_cat_mod=y&project_cat_id='.db_result($result, $j, 'group_project_id').'">';
759 $link = $linkend = '';
762 $link = $linkend = '';
764 echo '<td>'.$link . db_result($result, $j, $i) . $linkend.'</td>';
776 * validate_email() - Validate an email address
778 * @param string The address string to validate
779 * @returns true on success/false on error
782 function validate_email ($address) {
783 return (ereg('^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+'. '@'. '[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.' . '[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$', $address) !== false);
787 * validate_emails() - Validate a list of e-mail addresses
789 * @param string E-mail list
790 * @param char Separator
791 * @returns array Array of invalid e-mail addresses (if empty, all addresses are OK)
793 function validate_emails ($addresses, $separator=',') {
794 if (strlen($addresses) == 0) return array();
796 $emails = explode($separator, $addresses);
799 if (is_array($emails)) {
800 foreach ($emails as $email) {
801 $email = trim($email); // This is done so we can validate lists like "a@b.com, c@d.com"
802 if (!validate_email($email)) $ret[] = $email;
811 * util_is_valid_filename() - Verifies whether a file has a valid filename
813 * @param string The file to verify
814 * @returns true on success/false on error
817 function util_is_valid_filename ($file) {
819 $invalidchars = eregi_replace("[-A-Z0-9+_\.]","",$file);
821 if (!empty($invalidchars)) {
824 if (strstr($file,'..')) {
833 * valid_hostname() - Validates a hostname string to make sure it doesn't contain invalid characters
835 * @param string The optional hostname string
836 * @returns true on success/false on failur
839 function valid_hostname ($hostname = "xyz") {
842 $invalidchars = eregi_replace("[-A-Z0-9\.]","",$hostname);
844 if (!empty($invalidchars)) {
848 //double dot, starts with a . or -
849 if (ereg("\.\.",$hostname) || ereg("^\.",$hostname) || ereg("^\-",$hostname)) {
853 $multipoint = explode(".",$hostname);
855 if (!(is_array($multipoint)) || ((count($multipoint) - 1) < 1)) {
865 * human_readable_bytes() - Translates an integer representing bytes to a human-readable format.
867 * Format file size in a human-readable way
868 * such as "xx Megabytes" or "xx Mo"
870 * @author Andrea Paleni <andreaSPAMLESS_AT_SPAMLESScriticalbit.com>
872 * @param int bytes is the size
873 * @param bool base10 enable base 10 representation, otherwise
874 * default base 2 is used
875 * @param int round number of fractional digits
876 * @param array labels strings associated to each 2^10 or
877 * 10^3(base10==true) multiple of base units
879 function human_readable_bytes ($bytes, $base10=false, $round=0, $labels=array(' bytes', ' KB', ' MB', ' GB')) {
880 if ($bytes <= 0 || !is_array($labels) || (count($labels) <= 0)) {
883 $step = $base10 ? 3 : 10;
884 $base = $base10 ? 10 : 2;
885 $log = (int)(log10($bytes)/log10($base));
887 foreach ($labels as $p=>$lab) {
892 if ($lab == " MB" or $lab == " GB") {
895 $text = round($bytes/pow($base,$pow),$round).$lab;
902 * ls - lists a specified directory and returns an array of files
903 * @param string the path of the directory to list
904 * @param boolean whether to filter out directories and illegal filenames
905 * @return array array of file names.
907 function &ls($dir,$filter=false) {
908 exec('ls -c1 '.$dir,$out);
910 for ($i=0; $i<count($out); $i++) {
911 if (util_is_valid_filename($out[$i]) && is_file($dir.'/'.$out[$i])) {
912 $filtered[]=$out[$i];
922 * readfile_chunked() - replacement for readfile
924 * @param string The file path
925 * @param bool Whether to return bytes served or just a bool
928 function readfile_chunked($filename, $returnBytes=true) {
929 $chunksize = 1*(1024*1024); // 1MB chunks
933 $handle = fopen($filename, 'rb');
934 if ($handle === false) {
938 while (!feof($handle)) {
939 $buffer = fread($handle, $chunksize);
944 $byteCounter += strlen($buffer);
947 $status = fclose($handle);
948 if ($returnBytes && $status) {
949 return $byteCounter; // return num. bytes delivered like readfile() does.
955 * util_is_root_dir() - Checks if a directory points to the root dir
956 * @param string Directory
959 function util_is_root_dir($dir) {
960 return !preg_match('/[^\\/]/',$dir);
964 * util_strip_accents() - Remove accents from given text.
968 function util_strip_accents($text) {
969 $find = utf8_decode($text);
971 utf8_decode('àáâãäçèéêëìíîïñòóôõöùúûüýÿÀÁÂÃÄÇÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜÝ'),
972 'aaaaaceeeeiiiinooooouuuuyyAAAAACEEEEIIIINOOOOOUUUUY');
973 return utf8_encode($find);
976 function normalized_urlprefix () {
977 $prefix = $GLOBALS['sys_urlprefix'] ;
978 $prefix = ereg_replace ("^/", "", $prefix) ;
979 $prefix = ereg_replace ("/$", "", $prefix) ;
980 $prefix = "/$prefix/" ;
986 function util_make_url ($path) {
987 if ($GLOBALS['sys_use_ssl'])
992 $url .= $GLOBALS['sys_default_domain'] ;
993 $url .= util_make_uri ($path) ;
997 function util_make_uri ($path) {
998 $path = ereg_replace ("^/", "", $path) ;
999 $uri .= normalized_urlprefix () ;
1004 function util_make_link ($path, $text, $extra_params=false, $absolute=false) {
1006 if (is_array($extra_params)) {
1007 foreach ($extra_params as $key => $value) {
1008 $ep .= "$key=\"$value\" ";
1012 return '<a ' . $ep . 'href="' . $path . '">' . $text . '</a>' ;
1014 return '<a ' . $ep . 'href="' . util_make_url ($path) . '">' . $text . '</a>' ;
1018 function util_make_link_u ($username, $user_id,$text) {
1019 return '<a href="' . util_make_url_u ($username, $user_id) . '">' . $text . '</a>' ;
1022 function util_make_url_u ($username, $user_id) {
1023 if (isset ($GLOBALS['sys_noforcetype']) && $GLOBALS['sys_noforcetype']) {
1024 return util_make_url ("/developer/?user_id=$user_id");
1026 return util_make_url ("/users/$username/");
1030 function util_make_link_g ($groupame, $group_id,$text) {
1031 return '<a href="' . util_make_url_g ($groupame, $group_id) . '">' . $text . '</a>' ;
1034 function util_make_url_g ($groupame, $group_id) {
1035 if (isset ($GLOBALS['sys_noforcetype']) && $GLOBALS['sys_noforcetype']) {
1036 return util_make_url ("/project/?group_id=$group_id");
1038 return util_make_url ("/projects/$groupame/");
1042 function util_ensure_value_in_set ($value, $set) {
1043 if (in_array ($value, $set)) {
1050 function check_email_available($group, $email, &$response) {
1051 // Check if a mailing list with same name already exists
1052 $mlFactory = new MailingListFactory($group);
1053 if (!$mlFactory || !is_object($mlFactory) || $mlFactory->isError()) {
1054 $response .= $mlFactory->getErrorMessage();
1057 $mlArray =& $mlFactory->getMailingLists();
1058 if ($mlFactory->isError()) {
1059 $response .= $mlFactory->getErrorMessage();
1062 for ($j = 0; $j < count($mlArray); $j++) {
1063 $currentList =& $mlArray[$j];
1064 if ($email == $currentList->getName()) {
1065 $response .= _('Error: a mailing list with the same email address already exists.');
1070 // Check if a forum with same name already exists
1071 $ff = new ForumFactory($group);
1072 if (!$ff || !is_object($ff) || $ff->isError()) {
1073 $response .= $ff->getErrorMessage();
1076 $farr =& $ff->getForums();
1077 $prefix = $group->getUnixName() . '-';
1078 for ($j = 0; $j < count($farr); $j++) {
1079 if (is_object($farr[$j])) {
1080 if ($email == $prefix . $farr[$j]->getName()) {
1081 $response .= _('Error: a forum with the same email address already exists.');
1087 // Email is available
1093 // c-file-style: "bsd"