4 * THIS FILE SHOULD ONLY INCLUDE SMALL USEFUL FUNCTIONS
7 if (!function_exists('ereg')) {
8 /** removed from php 7.0.0 */
9 function ereg($pattern, $line, &$match = array()) {
10 return preg_match('/'.$pattern.'/', $line, $match);
15 * pushes some data in the debug variable
17 function nt_common_add_debug($data)
21 if (is_array($data)) $nel_debug[] = print_r($data,true);
22 else $nel_debug[] = $data;
26 * redirects to a defined url
28 function nt_common_redirect($url)
31 if (substr($url,0,1) == '/') $url = substr($url,1);
33 $redirect = NELTOOL_SITEBASE
. $url;
35 header("Location: ". $redirect);
40 * adds a user action log
42 function nt_common_add_log($userinfo, $log_action, $log_desc)
46 $log_action = trim($log_action);
47 $log_desc = trim($log_desc);
49 if (!is_array($userinfo) && (!isset($userinfo['user_id']))) return false;
50 if ($log_action == '') return false;
51 if ($log_desc == '') return false;
53 $sql = "INSERT INTO ". NELDB_LOG_TABLE
." ('log_user_id','log_action','log_description','log_date','log_ip') VALUES ('". $userinfo['user_id'] ."','". addslashes($log_action) ."','". addslashes($log_desc) ."','". time() ."','". $NELTOOL['SERVER_VARS']['REMOTE_ADDR'] ."')";
60 if (!function_exists('array_combine'))
62 function array_combine( $keys, $vals )
64 $keys = array_values( (array) $keys );
65 $vals = array_values( (array) $vals );
66 $n = max( count( $keys ), count( $vals ) );
68 for( $i=0; $i<$n; $i++
)
70 $r[ $keys[ $i ] ] = $vals[ $i ];
76 if (!function_exists('array_chunk')) {
78 function array_chunk($input,$size,$preserve_keys=false)
84 while (@list
($key,$value) = @each
($input))
86 if( !( isset( $chunks[$i] ) ) )
88 $chunks[$i] = array();
91 if( count( $chunks[$i] ) < $size )
95 $chunks[$i][$key] = $value;
100 $chunks[$i][] = $value;
109 $chunks[$i][$key] = $value;
115 $chunks[$i][$j] = $value;
124 function array_natsort_list($array)
126 // for all arguments without the first starting at end of list
127 for ($i=func_num_args();$i>1;$i--)
129 // get column to sort by
130 $sort_by = func_get_arg($i-1);
133 $new_array = array();
134 $temporary_array = array();
136 // walk through original array
137 foreach($array as $original_key => $original_value)
139 // and save only values
140 $temporary_array[] = $original_value[$sort_by];
143 // sort array on values
144 natsort($temporary_array);
146 // delete double values
147 $temporary_array = array_unique($temporary_array);
149 // walk through temporary array
150 foreach($temporary_array as $temporary_value)
152 // walk through original array
153 foreach($array as $original_key => $original_value)
155 // and search for entries having the right value
156 if($temporary_value == $original_value[$sort_by])
159 $new_array[$original_key] = $original_value;
164 // update original array
171 function nt_common_assert( $script, $line, $message )
173 nt_common_add_debug('ASSERT ('. $script .':'. $line .') : '. ereg_replace( '^.*//\*', '', $message ));
177 function nt_log($data)
182 $log_user_name = $nel_user['user_name'];
184 $log_data = addslashes(trim($data));
186 $sql = "INSERT INTO ". NELDB_LOG_TABLE
." (`logs_user_name`,`logs_date`,`logs_data`) VALUES ('". $log_user_name ."','". $log_date ."','". $log_data ."')";
187 $db->sql_query($sql);
190 function nt_sleep($delay)
198 function nt_email($subject,$message,$emails=null)
200 if ($message !== '' && $subject !== '')
202 if ($emails === null)
204 $emails = 'vl@ryzom.com';
206 elseif (is_array($emails))
208 $emails = implode(', ', $emails);
211 $headers = "From: vl@ryzom.com\r\nReply-To: vl@ryzom.com\r\nX-Mailer: Shard Admin Tool\r\n";
212 mail($emails, $subject, $message, $headers);