[go: up one dir, main page]

Menu

[r19]: / tags / 0.58 / lib / misc.php  Maximize  Restore  History

Download this file

249 lines (178 with data), 6.7 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<?
/********************************************************************************************/
//
// Filename:
// misc.php
//
// Summary:
// this file contains functions common to both prospect and contract applications
// They should still be somewhat generic
//
// Modified:
//
// 09-02-2004
// Code cleanup. Moved functions that don't belong out
//
// 04-19-2006
// -More consolidation of functions.
// -merged function.inc.php into file
// -Created new files for removed functions
// *file_functions.inc.php
// *sanitize.inc.php
// *calc_functions.inc.php
// -Renamed file from common.inc.php to misc.php
//
//
/*********************************************************************************************/
/*********************************************************
// returns the type of browser the user is using.
// this function must be passed $HTTP_USER_AGENT.
*********************************************************/
function browser_check($var) {
if (eregi("MSIE",$var)) {
$browser_type="ie";
}
else {
$browser_type="mozilla";
}
echo strpos($HTTP_USER_AGENT,"MSIE");
return $browser_type;
}
/*********************************************************
*********************************************************/
function login_return($conn,$id) {
//return anonymous if there is no id
if ($id=="0" || !$id) return SITE_ADMIN;
$sql = "SELECT login FROM auth_accounts WHERE id='$id'";
if ($value = single_result($conn,$sql)) return $value["login"];
else return false;
}
/*********************************************************
*********************************************************/
function selfClose($url = null) {
//set to refresh the parent if url is not specified
if (!$url) $url = "window.opener.location.href";
else $url = "\"".$url."\"";
echo "<script type=\"text/javascript\">
var url = ".$url.";
window.opener.location.href = url;
self.close();
</script>
";
}
/*********************************************************
*********************************************************/
function selfFocus() {
echo "<script type=\"text/javascript\">\n";
echo "self.focus();\n";
echo "</script>\n";
}
/*********************************************************
*********************************************************/
function includeStylesheet($path) {
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"".$path."\">\n";
}
/*********************************************************
*********************************************************/
function includeJavascript($path) {
echo "<script src=\"".$path."\"></script>\n";
}
/*********************************************************
*********************************************************/
function preventCache() {
Header("Cache-control: private, no-cache");
Header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
Header("Pragma: no-cache");
}
/*********************************************************
*********************************************************/
function translateHtmlEntities($string) {
$trans_tbl = get_html_translation_table(HTML_ENTITIES);
$trans_tbl = array_flip($trans_tbl);
$original = strtr($string,$trans_tbl);
return $original;
}
/*************************************************************************************
// checkStrongPassword:
// checks the password to see if it is considered difficult to crack.
// Returns a string containing what it thinks is wrong with your password.
// If "strong password" is returned, then all is well. cracklib must be
// compiled into php, or this will generate a php error
**************************************************************************************/
function checkStrongPassword($conn,$accountId,$pwd) {
//if there is no accountId, return false since we can't check against the username
if (!$accountId) return "no account id specified";
$info = returnAccountInfo($conn,$accountId,null);
$login = &$info["login"];
$fn = &$info["first_name"];
$ln = &$info["last_name"];
//make sure the user's first name, last name, and login aren't in the password
if (stristr($pwd,$login)) return "it contains your username";
if (stristr($pwd,$fn)) return "it contains your name";
if (stristr($pwd,$ln)) return "it contains your name";
// Perform password check with craclib
$check = crack_check($pwd);
// Retrieve messages from cracklib
return crack_getlastmessage();
}
function dbInsertQuery($conn,$table,$option,$idField = "id") {
$ignoreArray = array("conn","table","debug","query");
$keys = array_keys($option);
$fieldString = null;
$valueString = null;
for ($row=0;$row<count($keys);$row++) {
$field = $keys[$row];
$value = $option[$field];
if (!in_array($field,$ignoreArray) && $value!=null) {
$fieldString .= $field.",";
$valueString .= "'".$value."',";
}
}
if ($fieldString && $valueString) {
$fieldString = substr($fieldString,0,strlen($fieldString) - 1);
$valueString = substr($valueString,0,strlen($valueString) - 1);
$sql = "INSERT INTO $table (".$fieldString.") VALUES (".$valueString.");";
if ($option["debug"]) echo $sql."<br>\n";
if ($option["query"]) return $sql;
if ($result = db_query($conn,$sql)) {
$returnId = db_insert_id($table,$idField,$conn,$result);
if ($returnId) return $returnId;
else return true;
} else return false;
} else return false;
}
function dbUpdateQuery($conn,$table,$option,$sanitize = null) {
$ignoreArray = array("conn","table","where","debug","query");
$keys = array_keys($option);
$queryString = null;
for ($row=0;$row<count($keys);$row++) {
$field = $keys[$row];
$value = $option[$field];
if (!in_array($field,$ignoreArray)) {
if ($value!=null) {
if ($sanitize)
$queryString .= $field."='".sanitize($value)."',";
else
$queryString .= $field."='".$value."',";
}
else $queryString .= $field."=NULL,";
}
}
if ($queryString) {
$queryString = substr($queryString,0,strlen($queryString) - 1);
$sql = "UPDATE $table SET ".$queryString." WHERE ".$option["where"];
if ($option["debug"]) echo $sql."<br>\n";
if ($option["query"]) return $sql;
if (db_query($conn,$sql)) return true;
else return false;
} else return false;
}
function debug($level,$msg) {
if (php_sapi_name()=="cli") $sep = "\n";
else $sep = "<br>";
if (defined("DEBUG") && DEBUG >= $level) {
//if from webdav then use webdav function
if (class_exists("webdavfunc")) webdavfunc::checkOutput($msg."\n");
else echo $msg.$sep;
}
}