| [ PHPXref.com ] | [ Generated: Sun Jul 20 19:16:27 2008 ] | [ Owl Intranet 0.82 ] |
| [ Index ] [ Variables ] [ Functions ] [ Classes ] [ Constants ] [ Statistics ] | ||
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * owl.lib.php 5 * 6 * Author: Steve Bourgeois <owl@bozzit.com> 7 * Project Founder: Chris Vincent <cvincent@project802.net> 8 * 9 * Copyright (c) 1999-2005 The Owl Project Team 10 * Licensed under the GNU GPL. For full terms see the file COPYING. 11 * 12 * $Id: owl.lib.php,v 1.58 2006/01/09 12:18:34 b0zz Exp $ 13 */ 14 15 // 16 // Controle the level of PHP Messages that are 17 // Reported 18 19 if ($default->debug == true) 20 { 21 // error_reporting (E_ERROR | E_WARNING | E_PARSE | E_NOTICE); 22 // I think we have a bit of work to get Owl to run with E_NOTICE turned On ;-( 23 error_reporting (E_ERROR | E_WARNING | E_PARSE); 24 } 25 else 26 { 27 error_reporting (0); 28 } 29 // 30 // Support for reg.globals off WES 31 if (substr(phpversion(), 0, 5) >= "4.1.0") 32 { 33 //import_request_variables('pgc', 'owl_'); 34 import_request_variables('pgc'); 35 } 36 else 37 { 38 if (!EMPTY($_POST)) 39 { 40 extract($_POST); 41 } 42 else 43 { 44 extract($HTTP_POST_VARS); 45 } 46 if (!EMPTY($_GET)) 47 { 48 extract($_GET); 49 } 50 else 51 { 52 extract($HTTP_GET_VARS); 53 } 54 if (!EMPTY($_FILE)) 55 { 56 extract($_FILE); 57 } 58 else 59 { 60 extract($HTTP_POST_FILES); 61 } 62 } 63 64 if(!empty($_GET[currentdb])) 65 { 66 $default->owl_current_db = $_GET[currentdb]; 67 } 68 else 69 { 70 if(!empty($_POST[currentdb])) 71 { 72 $default->owl_current_db = $_POST[currentdb]; 73 } 74 else 75 { 76 if(empty($default->owl_current_db)) 77 { 78 $default->owl_current_db = 0; 79 } 80 } 81 } 82 83 if(!isset($default->owl_FileDir)) 84 { 85 $default->owl_FileDir = $default->owl_db_FileDir[$default->owl_default_db]; 86 } 87 88 if (!isset($sess)) 89 { 90 if (!isset($HTTP_COOKIE_VARS["owl_sessid"])) 91 { 92 $sess = 0; 93 } 94 else 95 { 96 $sess = $HTTP_COOKIE_VARS["owl_sessid"]; 97 } 98 } 99 else 100 { 101 if (isset($HTTP_COOKIE_VARS["owl_sessid"])) 102 { 103 $sess = $HTTP_COOKIE_VARS["owl_sessid"]; 104 } 105 } 106 107 if (!isset($loginname)) 108 { 109 $loginname = 0; 110 } 111 if (!isset($login)) 112 { 113 $login = 0; 114 } 115 116 class Owl_DB extends DB_Sql 117 { 118 var $classname = "Owl_DB"; 119 // BEGIN wes changes -- moved these settings to config/owl.php 120 // Server where the database resides 121 var $Host = ""; 122 // Database name 123 var $Database = ""; 124 // User to access database 125 var $User = ""; 126 // Password for database 127 var $Password = ""; 128 129 function Owl_DB() 130 { 131 global $default; 132 133 if(empty($default->owl_current_db)) 134 { 135 $db = $default->owl_default_db; 136 } 137 else 138 { 139 $db = $default->owl_current_db; 140 } 141 142 $this->Host = $default->owl_db_host[$db]; 143 $this->Database = $default->owl_db_name[$db]; 144 $this->User = $default->owl_db_user[$db]; 145 $this->Password = $default->owl_db_pass[$db]; 146 147 148 //$this->Host = $default->owl_db_host[0]; 149 //$this->Database = $default->owl_db_name[0]; 150 //$this->User = $default->owl_db_user[0]; 151 //$this->Password = $default->owl_db_pass[0]; 152 } 153 // END wes changes 154 function haltmsg($msg) 155 { 156 printf("</td></table><b>$owl_lang->err_database:</b> %s<br>\n", $msg); 157 printf("<b>$owl_lang->err_sql</b>: %s (%s)<br>\n", 158 $this->Errno, $this->Error); 159 } 160 } 161 162 163 if(!empty($sess)) 164 { 165 foreach ( $default->owl_db_id as $database ) 166 { 167 $default->owl_current_db = $database; 168 169 $sql = new Owl_DB; 170 $sql->query("SELECT * from $default->owl_sessions_table where sessid = '$sess'"); 171 $sql->next_record(); 172 $numrows = $sql->num_rows($sql); 173 if ($numrows == 1) 174 { 175 break; 176 } 177 $default->owl_current_db = null; 178 } 179 } 180 181 getprefs(); 182 getuserprefs(); 183 184 // 185 // Set the language from default or from the users file. 186 // NOTE: the messages here cannot be internationalized 187 // 188 189 if (!isset($default->sButtonStyle)) 190 { 191 $default->sButtonStyle = $default->system_ButtonStyle; 192 } 193 194 gethtmlprefs(); 195 196 if (isset($default->owl_lang)) 197 { 198 $langdir = "$default->owl_fs_root/locale/$default->owl_lang"; 199 if (is_dir("$langdir") != 1) 200 { 201 die("<br /><font size='4'><center>Path to the 'locale' directory was Not found: $langdir</center></font>"); 202 } 203 else 204 { 205 $sql = new Owl_DB; 206 $sql->query("SELECT * from $default->owl_sessions_table where sessid = '$sess'"); 207 $sql->next_record(); 208 $numrows = $sql->num_rows($sql); 209 $getuid = $sql->f("usid"); 210 if ($numrows == 1) 211 { 212 $sql->query("SELECT * from $default->owl_users_table where id = $getuid"); 213 $sql->next_record(); 214 $language = $sql->f("language"); 215 $default->sButtonStyle = $sql->f("buttonstyle"); 216 if (!$language) 217 { 218 $language = $default->owl_lang; 219 } 220 if (file_exists("$default->owl_fs_root/locale/$language/language.inc")) 221 { 222 if (is_readable("$default->owl_fs_root/locale/$language/language.inc")) 223 { 224 require_once("$default->owl_fs_root/locale/$language/language.inc"); 225 $default->owl_lang = $language; 226 if (!empty($owl_lang->charset)) 227 { 228 $default->charset = $owl_lang->charset; 229 } 230 } 231 else 232 { 233 die("<br /><font size='4'><center>The webserver does not have read access to: 234 <br />The Language file '$default->owl_fs_root/locale/$language/language.inc' 235 <br />Please fix the permissions and try again</center></font>"); 236 } 237 } 238 else 239 { 240 die("<br /><font size='4'><center>The Language file '$default->owl_fs_root/locale/$language/language.inc' does not exists.</center></font>"); 241 } 242 } 243 else 244 { 245 if ($sess == 0) 246 { 247 $language = $default->owl_lang; 248 } 249 if (file_exists("$default->owl_fs_root/locale/$default->owl_lang/language.inc")) 250 { 251 if (is_readable("$default->owl_fs_root/locale/$default->owl_lang/language.inc")) 252 { 253 require_once("$default->owl_fs_root/locale/$default->owl_lang/language.inc"); 254 } 255 else 256 { 257 die("<br /><font size='4'><center>The webserver does not have read access to: 258 <br />The Language file '$default->owl_fs_root/locale/$default->owl_lang/language.inc'. 259 <br />Please fix the permissions and try again</center></font>"); 260 } 261 } 262 else 263 { 264 die("<br /><font size='4'><center>The Language file '$default->owl_fs_root/locale/$default->owl_lang/language.inc' does not exists.</center></font>"); 265 } 266 } 267 } 268 } 269 else 270 { 271 die("<br /><font size='4'><center>Unable to find language, please specify in config/owl.php.</center></font>"); 272 } 273 274 class Owl_Session 275 { 276 var $sessid; 277 var $sessuid; 278 var $sessdata; 279 280 function Open_Session($sessid = 0, $sessuid = 0) 281 { 282 global $default; 283 global $rememberme; 284 $this->sessid = $sessid; 285 $this->sessuid = $sessuid; 286 287 if ($sessid == "0") // if there is no user loged in, then create a session for them 288 { 289 290 $current = time(); 291 $random = $this->sessuid . $current; 292 $this->sessid = md5($random); 293 294 295 $OpenSess = new Owl_DB; 296 297 if (getenv("HTTP_CLIENT_IP")) 298 { 299 $ip = getenv("HTTP_CLIENT_IP"); 300 } 301 elseif (getenv("HTTP_X_FORWARDED_FOR")) 302 { 303 $forwardedip = getenv("HTTP_X_FORWARDED_FOR"); 304 list($ip, $ip2, $ip3, $ip4) = split (",", $forwardedip); 305 } 306 else 307 { 308 $ip = getenv("REMOTE_ADDR"); 309 } 310 311 if (!$default->active_session_ip) 312 { 313 $ip = 0; 314 } 315 316 if ($rememberme == 1) 317 { 318 $current = time() +60*60*24*$default->cookie_timeout; 319 } 320 321 if (empty($_POST[currentdb])) 322 { 323 $iCurrentDB = "0"; 324 } 325 else 326 { 327 $iCurrentDB = $_POST[currentdb]; 328 } 329 330 $result = $OpenSess->query("INSERT INTO $default->owl_sessions_table VALUES ('$this->sessid', '$this->sessuid', '$current', '$ip', '$iCurrentDB')"); 331 332 if (!$result) 333 { 334 die("$owl_lang->err_sess_write"); 335 } 336 337 if ($rememberme == 1 and $default->remember_me) 338 { 339 setcookie ("owl_sessid", $this->sessid, time()+60*60*24*$default->cookie_timeout); 340 } 341 } 342 // else we have a session id, try to validate it... 343 $CheckSess = new Owl_DB; 344 $CheckSess->query("SELECT * FROM $default->owl_sessions_table WHERE sessid = '$this->sessid'"); 345 // any matching session ids? 346 $numrows = $CheckSess->num_rows($CheckSess); 347 if (!$numrows) die("$owl_lang->err_sess_notvalid"); 348 // return if we are a.o.k. 349 while ($CheckSess->next_record()) 350 { 351 $this->sessdata["sessid"] = $CheckSess->f("sessid"); 352 } 353 return $this; 354 } 355 } 356 357 function fCheckIfReviewer ($file_id) 358 { 359 global $default, $userid; 360 $dbCheck = new Owl_DB; 361 362 $dbCheck->query("SELECT file_id from $default->owl_peerreview_table where reviewer_id = '$userid' and file_id = '$file_id' "); 363 if ($dbCheck->num_rows() > 0) 364 { 365 return true; 366 } 367 return false; 368 } 369 370 function fCountFileType ($id, $type) 371 { 372 global $default, $userid; 373 $GetItems = new Owl_DB; 374 375 $GetItems->query("SELECT id FROM $default->owl_files_table WHERE url = '$type' AND parent = '$id' AND approved = '1'"); 376 377 if ($default->restrict_view == 1) 378 { 379 while ($GetItems->next_record()) 380 { 381 $bFileDownload = check_auth($GetItems->f("id"), "file_download", $userid, false, false); 382 if ($bFileDownload) 383 { 384 $iFileCount++; 385 } 386 } 387 } 388 else 389 { 390 $iFileCount = $GetItems->num_rows(); 391 } 392 return $iFileCount; 393 } 394 395 // -------------------------------- 396 function check_for_sess ($uid) 397 { 398 global $default; 399 400 $mysess = 0; 401 $sql = new Owl_DB; 402 $sql->query("SELECT * from $default->owl_sessions_table where usid = '$uid' and ip = '0' ORDER BY lastused ASC"); 403 while ($sql->next_record()) 404 { 405 $time = time(); 406 if (($time - $sql->f("lastused")) <= $default->owl_timeout) 407 { 408 $mysess = $sql->f("sessid"); 409 if (!($default->remember_me)) 410 { 411 $sql->query("UPDATE $default->owl_sessions_table set lastused = '$time' where sessid = '$mysess'"); 412 } 413 break; 414 } 415 } 416 if ($mysess == 0) 417 { 418 $session = new Owl_Session; 419 $userid = $session->Open_Session(0, $uid); 420 $mysess = $userid->sessdata["sessid"]; 421 $sql->query("UPDATE $default->owl_sessions_table set ip = '0' where sessid = '$mysess'"); 422 } 423 return $mysess; 424 } 425 426 function notify_file_owner($iFileId, $comment) 427 { 428 global $default, $userid; 429 //global $owl_lang; 430 431 $sql = new Owl_DB; 432 $getuser = new Owl_DB; 433 434 $sql->query("SELECT * from $default->owl_files_table where id = '$iFileId'"); 435 436 $sql->next_record(); 437 438 $iCreatorId = $sql->f("creatorid"); 439 $sFileName = $sql->f("filename"); 440 $iParent = $sql->f("parent"); 441 442 $getuser->query("SELECT language, email,comment_notify,name from $default->owl_users_table where id = '$iCreatorId' and disabled = '0'"); 443 $getuser->next_record(); 444 445 if ($getuser->f("comment_notify") == 1 and $userid <> $iCreatorId) 446 { 447 $language = $getuser->f("language"); 448 if (empty($language)) 449 { 450 $language = $default->owl_lang; 451 } 452 if (file_exists("$default->owl_fs_root/locale/$language/language.inc")) 453 { 454 include("$default->owl_fs_root/locale/$language/language.inc"); 455 } 456 $mail = new phpmailer(); 457 if ($default->use_smtp) 458 { 459 $mail->IsSMTP(); // set mailer to use SMTP 460 if ($default->use_smtp_auth) 461 { 462 $mail->SMTPAuth = "true"; // turn on SMTP authentication 463 $mail->Username = "$default->smtp_auth_login "; // SMTP username 464 $mail->Password = "$default->smtp_passwd"; // SMTP password 465 } 466 } 467 $mail->CharSet = "$owl_lang->charset"; // set the email charset to the language file charset 468 $mail->Host = "$default->owl_email_server"; // specify main and backup server 469 $mail->From = "$default->owl_email_from"; 470 $mail->FromName = "$default->owl_email_fromname"; 471 $mail->AddAddress($getuser->f("email")); 472 $mail->AddReplyTo("$default->owl_email_replyto", "OWL Intranet"); 473 $mail->WordWrap = 50; // set word wrap to 50 characters 474 $mail->IsHTML(true); // set email format to HTML 475 $mail->Subject = "$default->owl_email_subject $owl_lang->notif_subject_comment"; 476 $mail->Body = "<html><body>" . "$owl_lang->notif_salutation " . $getuser->f("name") . ",<br /><br />"; 477 $mail->Body .= uid_to_name($userid) . " $owl_lang->notif_comment_1 " . get_dirpath($iParent) . "/" . $sFileName . "<br /><br />"; 478 $mail->Body .= "$owl_lang->notif_comment_2<br /><br />"; 479 $mail->Body .= nl2br($comment) . "<br /><br /><br />"; 480 $mail->Body .= "</body></html>"; 481 482 $mail->Body .= "</body></html>"; 483 if (!$mail->Send() && $default->debug == true) 484 { 485 printError("DEBUG: " . $owl_lang->err_email, $mail->ErrorInfo); 486 } 487 } 488 } 489 490 function notify_monitored_folders ($parent, $filename) 491 { 492 global $default, $userid; 493 //global $owl_lang; 494 495 $sql = new Owl_DB; 496 $getuser = new Owl_DB; 497 // For each user that want to receive notification of an UPDATE of this file 498 499 $sql->query("SELECT f.id, fid, name, description, parent, userid, filename from $default->owl_files_table f, $default->owl_monitored_folder_table m where f.filename = '$filename' and f.parent = '$parent' and m.fid = '$parent'"); 500 501 while ($sql->next_record()) 502 { 503 $CurrentUser = $sql->f("userid"); 504 $getuser->query("SELECT id, email,language,attachfile from $default->owl_users_table where id = '$CurrentUser' and disabled = '0'"); 505 $getuser->next_record(); 506 507 if (check_auth($sql->f("id"), "file_download", $getuser->f(id)) == 1 and $getuser->f(id) != $userid) 508 { 509 // END BUG 548994 More Below 510 $path = find_path($sql->f("parent")); 511 $filename = $sql->f("filename"); 512 // $newpath = ereg_replace(" ","%20",$path); 513 $newpath = $path; 514 // $newfilename = ereg_replace(" ","%20",$sql->f("filename")); 515 $newfilename = $sql->f("filename"); 516 $DefUserLang = $getuser->f("language"); 517 if(empty($DefUserLang)) 518 { 519 $DefUserLang = $default->owl_lang; 520 } 521 require("$default->owl_fs_root/locale/$DefUserLang/language.inc"); 522 523 $r = preg_split("(\;|\,)", $getuser->f("email")); 524 reset ($r); 525 while (list ($occ, $email) = each ($r)) 526 { 527 $tempsess = check_for_sess($getuser->f("id")); 528 529 $mail = new phpmailer(); 530 if ($default->use_smtp) 531 { 532 $mail->IsSMTP(); // set mailer to use SMTP 533 if ($default->use_smtp_auth) 534 { 535 $mail->SMTPAuth = "true"; // turn on SMTP authentication 536 $mail->Username = "$default->smtp_auth_login "; // SMTP username 537 $mail->Password = "$default->smtp_passwd"; // SMTP password 538 } 539 } 540 $mail->CharSet = "$owl_lang->charset"; // set the email charset to the language file charset 541 $mail->Host = "$default->owl_email_server"; // specify main and backup server 542 $mail->From = "$default->owl_email_from"; 543 $mail->FromName = "$default->owl_email_fromname"; 544 $mail->AddAddress($email); 545 $mail->AddReplyTo("$default->owl_email_replyto", "OWL Intranet"); 546 $mail->WordWrap = 50; // set word wrap to 50 characters 547 $mail->IsHTML(true); // set email format to HTML 548 $mail->Subject = "$default->owl_email_subject $owl_lang->notif_subject_monitor"; 549 if ($type != "url") 550 { 551 if ($getuser->f("attachfile") == 1) 552 { 553 //$desc = ereg_replace("[\\]", "", $sql->f("description")); 554 $desc = stripslashes($sql->f("description")); 555 $mail->Body = "<html><body>" . "$owl_lang->notif_msg<br /><br />" . "$owl_lang->title: " . $sql->f("name") . "<br /><br />$owl_lang->description: $desc <br /><br />"; 556 $mail->Body .= $owl_lang->owl_path . $path . "/" . $filename; 557 $mail->Body .= "<br /><br />" . $owl_lang->notif_user . " " .uid_to_name($userid); 558 //$mail->altBody = "$owl_lang->notif_msg_alt\n\n" . "$owl_lang->title: " . $sql->f("name") . "\n\n $owl_lang->description: $desc \n\n"; 559 //$mail->altBody .= $owl_lang->owl_path . $path . "/" . $filename; 560 if (!$default->owl_use_fs) 561 { 562 if (file_exists("$default->owl_FileDir/$filename")) 563 { 564 unlink("$default->owl_FileDir/$filename"); 565 } 566 $file = fopen("$default->owl_FileDir/$filename", 'wb'); 567 $getfile = new Owl_DB; 568 $getfile->query("SELECT data,compressed from $default->owl_files_data_table where id='$fid'"); 569 while ($getfile->next_record()) 570 { 571 if ($getfile->f("compressed")) 572 { 573 $tmpfile = $default->owl_tmpdir . "/owltmp.$fid.gz"; 574 $uncomptmpfile = $default->owl_tmpdir . "/owltmp.$fid"; 575 if (file_exists($tmpfile)) unlink($tmpfile); 576 577 $fp = fopen($tmpfile, "w"); 578 fwrite($fp, $getfile->f("data")); 579 fclose($fp); 580 581 system($default->gzip_path . " -df $tmpfile"); 582 583 $fsize = filesize($uncomptmpfile); 584 $fd = fopen($uncomptmpfile, 'rb'); 585 $filedata = fread($fd, $fsize); 586 fclose($fd); 587 588 fwrite($file, $filedata); 589 unlink($uncomptmpfile); 590 } 591 else 592 { 593 fwrite($file, $getfile->f("data")); 594 } 595 } 596 fclose($file); 597 // $mail->AddAttachment("$default->owl_FileDir/$newfilename"); 598 $mimeType = fGetMimeType($newfilename); 599 $mail->AddAttachment("$default->owl_FileDir/$newfilename", "" , "base64" , "$mimeType"); 600 } 601 else 602 { 603 $mimeType = fGetMimeType($newfilename); 604 $mail->AddAttachment("$default->owl_FileDir/$newpath/$newfilename", "" , "base64" , "$mimeType"); 605 // $mail->AddAttachment("$default->owl_FileDir/$newpath/$newfilename"); 606 } 607 } 608 else 609 { 610 //$desc = ereg_replace("[\\]", "", $sql->f("description")); 611 $desc = stripslashes($sql->f("description")); 612 $link = $default->owl_notify_link . "browse.php?sess=$tempsess&parent=" . $sql->f("parent") . "&expand=1&fileid=" . $sql->f("fid"); 613 $mail->Body = "<html><body>" . "$owl_lang->notif_msg<br /><br />" . "$owl_lang->title: " . $sql->f("name") . "<br /><br />URL: <A HREF=" . $link . ">" . $link . "</A><br /><br />$owl_lang->description: $desc <br /><br />"; 614 $mail->Body .= $owl_lang->owl_path . $path . "/" . $filename; 615 $mail->Body .= "<br /><br />" . $owl_lang->notif_user . " " .uid_to_name($userid); 616 //$mail->altBody = "$owl_lang->notif_msg_alt\n\n" . "$owl_lang->title: " . $sql->f("name") . "\n\n $owl_lang->description: $desc \n\n"; 617 //$mail->altBody .= $owl_lang->owl_path . $path . "/" . $filename; 618 } 619 } 620 else 621 { 622 $desc = stripslashes($sql->f("description")); 623 //$desc = ereg_replace("[\\]", "", $sql->f("description")); 624 $mail->Body = "<html><body>" . "URL: <A HREF=" . $newfilename . ">" . $newfilename . "</A> <br /><br />$owl_lang->notif_msg<br /><br />" . "$owl_lang->title: " . $sql->f("name") . "<br /><br />$owl_lang->description: $desc <br /><br />"; 625 $mail->Body .= $owl_lang->owl_path . $path . "/" . $filename; 626 $mail->Body .= "<br /><br />" . $owl_lang->notif_user . " " .uid_to_name($userid); 627 //$mail->altBody = "URL: $newfilename \n\n$owl_lang->notif_msg_alt\n\n" . "$owl_lang->title: " . $sql->f("name") . "\n\n $owl_lang->description: $desc \n\n"; 628 //$mail->altBody .= $owl_lang->owl_path . $path . "/" . $filename; 629 } 630 $mail->Body .= "</body></html>"; 631 if (!$mail->Send() && $default->debug == true) 632 { 633 printError("DEBUG: " . $owl_lang->err_email, $mail->ErrorInfo); 634 } 635 if (!$default->owl_use_fs && $sql->f("attachfile") == 1) 636 { 637 unlink("$default->owl_FileDir/$newfilename"); 638 } 639 } 640 } 641 } 642 } 643 // -------------------------------- 644 function notify_monitored ($fid, $type) 645 { 646 global $default, $userid; 647 //global $owl_lang; 648 649 $sql = new Owl_DB; 650 $getuser = new Owl_DB; 651 // For each user that want to receive notification of an UPDATE of this file 652 653 $sql->query("SELECT * from $default->owl_files_table f, $default->owl_monitored_file_table m where f.id = m.fid and m.fid = '$fid'"); 654 655 while ($sql->next_record()) 656 { 657 $CurrentUser = $sql->f("userid"); 658 $getuser->query("SELECT id, email,language,attachfile from $default->owl_users_table where id = '$CurrentUser' and disabled = '0'"); 659 $getuser->next_record(); 660 661 if (check_auth($fid, "file_download", $getuser->f(id)) == 1 and $getuser->f(id) != $userid) 662 { 663 // END BUG 548994 More Below 664 $path = find_path($sql->f("parent")); 665 $filename = $sql->f("filename"); 666 $newpath = $path; 667 $newfilename = $sql->f("filename"); 668 $DefUserLang = $getuser->f("language"); 669 if(empty($DefUserLang)) 670 { 671 $DefUserLang = $default->owl_lang; 672 } 673 674 require("$default->owl_fs_root/locale/$DefUserLang/language.inc"); 675 676 $r = preg_split("(\;|\,)", $getuser->f("email")); 677 reset ($r); 678 while (list ($occ, $email) = each ($r)) 679 { 680 $tempsess = check_for_sess($getuser->f("id")); 681 682 $mail = new phpmailer(); 683 if ($default->use_smtp) 684 { 685 $mail->IsSMTP(); // set mailer to use SMTP 686 if ($default->use_smtp_auth) 687 { 688 $mail->SMTPAuth = "true"; // turn on SMTP authentication 689 $mail->Username = "$default->smtp_auth_login "; // SMTP username 690 $mail->Password = "$default->smtp_passwd"; // SMTP password 691 } 692 } 693 $mail->CharSet = "$owl_lang->charset"; // set the email charset to the language file charset 694 $mail->Host = "$default->owl_email_server"; // specify main and backup server 695 $mail->From = "$default->owl_email_from"; 696 $mail->FromName = "$default->owl_email_fromname"; 697 $mail->AddAddress($email); 698 $mail->AddReplyTo("$default->owl_email_replyto", "OWL Intranet"); 699 $mail->WordWrap = 50; // set word wrap to 50 characters 700 $mail->IsHTML(true); // set email format to HTML 701 $mail->Subject = "$default->owl_email_subject $owl_lang->notif_subject_monitor"; 702 if ($type != "url") 703 { 704 if ($getuser->f("attachfile") == 1) 705 { 706 //$desc = ereg_replace("[\\]", "", $sql->f("description")); 707 $desc = stripslashes($sql->f("description")); 708 $mail->Body = "<html><body>" . "$owl_lang->notif_msg<br /><br />" . "$owl_lang->title: " . $sql->f("name") . "<br /><br />$owl_lang->description: $desc <br /><br />"; 709 $mail->Body .= $owl_lang->owl_path . $path . "/" . $filename; 710 $mail->Body .= "<br /><br />" . $owl_lang->notif_user . " " .uid_to_name($userid); 711 //$mail->altBody = "$owl_lang->notif_msg_alt\n\n" . "$owl_lang->title: " . $sql->f("name") . "\n\n $owl_lang->description: $desc \n\n"; 712 //$mail->altBody .= $owl_lang->owl_path . $path . "/" . $filename; 713 if (!$default->owl_use_fs) 714 { 715 if (file_exists("$default->owl_FileDir/$filename")) 716 { 717 unlink("$default->owl_FileDir/$filename"); 718 } 719 $file = fopen("$default->owl_FileDir/$filename", 'wb'); 720 $getfile = new Owl_DB; 721 $getfile->query("SELECT data,compressed from $default->owl_files_data_table where id='$fid'"); 722 while ($getfile->next_record()) 723 { 724 if ($getfile->f("compressed")) 725 { 726 $tmpfile = $default->owl_tmpdir . "/owltmp.$fid.gz"; 727 $uncomptmpfile = $default->owl_tmpdir . "/owltmp.$fid"; 728 if (file_exists($tmpfile)) unlink($tmpfile); 729 730 $fp = fopen($tmpfile, "w"); 731 fwrite($fp, $getfile->f("data")); 732 fclose($fp); 733 734 system($default->gzip_path . " -df $tmpfile"); 735 736 $fsize = filesize($uncomptmpfile); 737 $fd = fopen($uncomptmpfile, 'rb'); 738 $filedata = fread($fd, $fsize); 739 fclose($fd); 740 741 fwrite($file, $filedata); 742 unlink($uncomptmpfile); 743 } 744 else 745 { 746 fwrite($file, $getfile->f("data")); 747 } 748 } 749 fclose($file); 750 $mimeType = fGetMimeType($newfilename); 751 $mail->AddAttachment("$default->owl_FileDir/$newfilename", "" , "base64" , "$mimeType"); 752 } 753 else 754 { 755 $mimeType = fGetMimeType($newfilename); 756 $mail->AddAttachment("$default->owl_FileDir/$newpath/$newfilename", "" , "base64" , "$mimeType"); 757 } 758 } 759 else 760 { 761 //$desc = ereg_replace("[\\]", "", $sql->f("description")); 762 $desc = stripslashes($sql->f("description")); 763 $link = $default->owl_notify_link . "browse.php?sess=$tempsess&parent=" . $sql->f("parent") . "&expand=1&fileid=" . $sql->f("fid"); 764 $mail->Body = "<html><body>" . "$owl_lang->notif_msg<br /><br />" . "$owl_lang->title: " . $sql->f("name") . "<br /><br />URL: <A HREF=" . $link . ">" . $link . "</A><br /><br />$owl_lang->description: $desc <br /><br />"; 765 $mail->Body .= $owl_lang->owl_path . $path . "/" . $filename; 766 $mail->Body .= "<br /><br />" . $owl_lang->notif_user . " " .uid_to_name($userid); 767 //$mail->altBody = "$owl_lang->notif_msg_alt\n\n" . "$owl_lang->title: " . $sql->f("name") . "\n\n $owl_lang->description: $desc \n\n"; 768 //$mail->altBody .= $owl_lang->owl_path . $path . "/" . $filename; 769 } 770 } 771 else 772 { 773 //$desc = ereg_replace("[\\]", "", $sql->f("description")); 774 $desc = stripslashes($sql->f("description")); 775 $mail->Body = "<html><body>" . "URL: <A HREF=" . $newfilename . ">" . $newfilename . "</A> <br /><br />$owl_lang->notif_msg<br /><br />" . "$owl_lang->title: " . $sql->f("name") . "<br /><br />$owl_lang->description: $desc <br /><br />"; 776 $mail->Body .= $owl_lang->owl_path . $path . "/" . $filename; 777 $mail->Body .= "<br /><br />" . $owl_lang->notif_user . " " .uid_to_name($userid); 778 //$mail->altBody = "URL: $newfilename \n\n$owl_lang->notif_msg_alt\n\n" . "$owl_lang->title: " . $sql->f("name") . "\n\n $owl_lang->description: $desc \n\n"; 779 //$mail->altBody .= $owl_lang->owl_path . $path . "/" . $filename; 780 } 781 $mail->Body .= "</body></html>"; 782 if (!$mail->Send() && $default->debug == true) 783 { 784 printError("DEBUG: " . $owl_lang->err_email, $mail->ErrorInfo); 785 } 786 if (!$default->owl_use_fs && $sql->f("attachfile") == 1) 787 { 788 unlink("$default->owl_FileDir/$newfilename"); 789 } 790 } 791 } 792 } 793 } 794 795 796 797 function notify_reviewer ($iUserId, $iFileId , $usermessage, $doc_action = "", $reason = "") 798 { 799 global $default, $userid; 800 801 $sql = new Owl_DB; 802 803 $sql->query("SELECT email,language,attachfile from $default->owl_users_table where id = '$iUserId'"); 804 $sql->next_record(); 805 806 $DefUserLang = $sql->f("language"); 807 if(empty($DefUserLang)) 808 { 809 $DefUserLang = $default->owl_lang; 810 } 811 812 $email = $sql->f("email"); 813 814 $sql->query("SELECT filename, name, description from $default->owl_files_table where id = '$iFileId'"); 815 $sql->next_record(); 816 817 $title = $sql->f("name"); 818 $desc = $sql->f("description"); 819 $filename = $sql->f("filename"); 820 821 require("$default->owl_fs_root/locale/$DefUserLang/language.inc"); 822 823 switch ($doc_action) 824 { 825 case "final_approved": 826 case "approved": 827 $email_subject = $owl_lang->peer_subj_approved; 828 $body = "$usermessage <br /><br />"; 829 if ($doc_action == "final_approved") 830 { 831 $body .= $owl_lang->peer_file_final . "<br /><br />"; 832 $body .= $owl_lang->peer_final_body . "<br />"; 833 } 834 835 $body .= "$owl_lang->peer_approved_body " .uid_to_name($userid) ." <br />"; 836 $body .= "$owl_lang->peer_file_approved $filename <br />"; 837 $body .= "$owl_lang->title: $title" . "<br />"; 838 $body .= $owl_lang->description .": " . $desc ."<br /><br />"; 839 break; 840 case "rejected": 841 $email_subject = $owl_lang->peer_subj_rejected; 842 $body = "$usermessage <br /><br />"; 843 $body .= "$owl_lang->peer_rejected_body " .uid_to_name($userid) ." <br />"; 844 $body .= "$owl_lang->peer_file_rejected $filename <br />"; 845 $body .= "$owl_lang->title: $title" . "<br />"; 846 $body .= $owl_lang->description .": " . $desc ."<br /><br />"; 847 $body .= "<br /><br />$owl_lang->peer_reject_reason: $reason" ; 848 break; 849 case "reminder": 850 $email_subject = $owl_lang->peer_subj_reminder; 851 break; 852 default: 853 $email_subject = $owl_lang->peer_subj_review; 854 $body = "$usermessage <br /><br />"; 855 $body .= "$owl_lang->peer_review_body<br />"; 856 $body .= "$owl_lang->peer_file_to_review $filename <br />"; 857 $body .= "$owl_lang->title: $title" . "<br />"; 858 $body .= $owl_lang->description .": " . $desc ."<br /><br />"; 859 $body .= $owl_lang->notif_user . ": " .uid_to_name($userid); 860 break; 861 } 862 863 $mail = new phpmailer(); 864 865 if ($default->use_smtp) 866 { 867 $mail->IsSMTP(); // set mailer to use SMTP 868 if ($default->use_smtp_auth) 869 { 870 $mail->SMTPAuth = "true"; // turn on SMTP authentication 871 $mail->Username = "$default->smtp_auth_login "; // SMTP username 872 $mail->Password = "$default->smtp_passwd"; // SMTP password 873 } 874 } 875 $mail->CharSet = "$owl_lang->charset"; // set the email charset to the language file charset 876 $mail->Host = "$default->owl_email_server"; // specify main and backup server 877 $mail->From = "$default->owl_email_from"; 878 $mail->FromName = "$default->owl_email_fromname"; 879 $mail->AddAddress($email); 880 $mail->AddReplyTo("$default->owl_email_replyto", "OWL Intranet"); 881 $mail->WordWrap = 50; // set word wrap to 50 characters 882 $mail->IsHTML(true); // set email format to HTML 883 884 $mail->Subject = $email_subject; 885 886 $mail->Body = "<html><body>"; 887 $mail->Body .= $body; 888 $mail->Body .= "</body></html>"; 889 890 if (!$mail->Send() && $default->debug == true) 891 { 892 printError("DEBUG: " . $owl_lang->err_email, $mail->ErrorInfo); 893 } 894 } 895 896 function notify_users($groupid, $flag, $parent, $filename, $title, $desc, $type) 897 { 898 global $default, $userid; 899 //global $owl_lang; 900 901 $sql = new Owl_DB; 902 $desc = stripslashes($desc); 903 $title = stripslashes($title); 904 905 $path = find_path($parent); 906 $sql->query("SELECT id from $default->owl_files_table where filename='$filename' AND parent='$parent'"); 907 $sql->next_record(); 908 $fileid = $sql->f("id"); 909 910 911 //$sql->query("SELECT distinct id, email,language,attachfile from $default->owl_users_table u left join $default->owl_users_grpmem_table m on u.id=m.userid where notify = 1 and (u.groupid = $groupid or m.groupid = $groupid)"); 912 $sql->query("SELECT distinct id, email,language,attachfile from $default->owl_users_table u left join $default->owl_users_grpmem_table m on u.id=m.userid where notify = '1' and disabled = '0' and (u.groupid='$groupid' or m.groupid='$groupid') and u.id <> '$userid'"); 913 914 while ($sql->next_record()) 915 { 916 if (check_auth($fileid, "file_download", $sql->f("id")) == 1) 917 { 918 $newpath = $path; 919 $newfilename = $filename; 920 $DefUserLang = $sql->f("language"); 921 if(empty($DefUserLang)) 922 { 923 $DefUserLang = $default->owl_lang; 924 } 925 require("$default->owl_fs_root/locale/$DefUserLang/language.inc"); 926 927 $r = preg_split("(\;|\,)", $sql->f("email")); 928 reset ($r); 929 while (list ($occ, $email) = each ($r)) 930 { 931 $mail = new phpmailer(); 932 // Create a temporary session id, the user 933 // will need to get to this file before 934 // the default session timeout 935 936 // $session = new Owl_Session; 937 $tempsess = check_for_sess($sql->f("id")); 938 939 if ($flag == 0) 940 { 941 if ($default->use_smtp) 942 { 943 $mail->IsSMTP(); // set mailer to use SMTP 944 if ($default->use_smtp_auth) 945 { 946 $mail->SMTPAuth = "true"; // turn on SMTP authentication 947 $mail->Username = "$default->smtp_auth_login "; // SMTP username 948 $mail->Password = "$default->smtp_passwd"; // SMTP password 949 } 950 } 951 $mail->CharSet = "$owl_lang->charset"; // set the email charset to the language file charset 952 $mail->Host = "$default->owl_email_server"; // specify main and backup server 953 $mail->From = "$default->owl_email_from"; 954 $mail->FromName = "$default->owl_email_fromname"; 955 $mail->AddAddress($email); 956 $mail->AddReplyTo("$default->owl_email_replyto", "OWL Intranet"); 957 $mail->WordWrap = 50; // set word wrap to 50 characters 958 $mail->IsHTML(true); // set email format to HTML 959 $mail->Subject = "$default->owl_email_subject $owl_lang->notif_subject_new"; 960 if ($type != "url") 961 { 962 if ($sql->f("attachfile") == 1) 963 { 964 $mail->Body = "<html><body>" . "$owl_lang->notif_msg<br /><br />" . "$owl_lang->title: $title" . "<br /><br />$owl_lang->description: $desc<br /><br />"; 965 $mail->Body .= $owl_lang->owl_path . $path . "/" . $filename; 966 $mail->Body .= "<br /><br />" . $owl_lang->notif_user . " " .uid_to_name($userid); 967 //$mail->altBody = "$owl_lang->notif_msg_alt\n\n" . "$owl_lang->title: $title" . "\n\n $owl_lang->description: $desc\n\n"; 968 //$mail->altBody .= $owl_lang->owl_path . $path . "/" . $filename; 969 970 if (!$default->owl_use_fs) 971 { 972 if (file_exists("$default->owl_FileDir/$filename")) 973 { 974 unlink("$default->owl_FileDir/$filename"); 975 } 976 $file = fopen("$default->owl_FileDir/$filename", 'wb'); 977 $getfile = new Owl_DB; 978 $getfile->query("SELECT data,compressed from $default->owl_files_data_table where id='$fileid'"); 979 while ($getfile->next_record()) 980 { 981 if ($getfile->f("compressed")) 982 { 983 $tmpfile = $default->owl_tmpdir . "/owltmp.$fileid.gz"; 984 $uncomptmpfile = $default->owl_tmpdir . "/owltmp.$fileid"; 985 if (file_exists($tmpfile)) unlink($tmpfile); 986 987 $fp = fopen($tmpfile, "w"); 988 fwrite($fp, $getfile->f("data")); 989 fclose($fp); 990 991 system($default->gzip_path . " -df $tmpfile"); 992 993 $fsize = filesize($uncomptmpfile); 994 $fd = fopen($uncomptmpfile, 'rb'); 995 $filedata = fread($fd, $fsize); 996 fclose($fd); 997 998 fwrite($file, $filedata); 999 unlink($uncomptmpfile); 1000 } 1001 else 1002 { 1003 fwrite($file, $getfile->f("data")); 1004 } 1005 } 1006 fclose($file); 1007 $mimeType = fGetMimeType($newfilename); 1008 $mail->AddAttachment("$default->owl_FileDir/$newfilename", "" , "base64" , "$mimeType"); 1009 } 1010 else 1011 { 1012 $mimeType = fGetMimeType($newfilename); 1013 $mail->AddAttachment("$default->owl_FileDir/$newpath/$newfilename", "" , "base64" , "$mimeType"); 1014 } 1015 } 1016 else 1017 { 1018 $link = $default->owl_notify_link . "browse.php?sess=$tempsess&parent=$parent&expand=1&fileid=$fileid"; 1019 $mail->Body = "<html><body>" . "$owl_lang->notif_msg_link<br /><br />" . "$owl_lang->title: " . $title . "<br /><br />URL: <A HREF=" . $link . ">" . $link . "</A><br /><br />$owl_lang->description: $desc<br /><br />"; 1020 $mail->Body .= $owl_lang->owl_path . $path . "/" . $filename; 1021 $mail->Body .= "<br /><br />" . $owl_lang->notif_user . " " .uid_to_name($userid); 1022 //$mail->altBody = "$owl_lang->notif_msg_alt\n\n" . "$owl_lang->title: $title" . "\n\n $owl_lang->description: $desc\n\n"; 1023 //$mail->altBody .= $owl_lang->owl_path . $path . "/" . $filename; 1024 } 1025 } 1026 else 1027 { 1028 $mail->Body = "<html><body>" . "URL: <A HREF=" . $newfilename . ">" . $newfilename . "</A> <br /><br />$owl_lang->notif_msg_link<br /><br />" . "$owl_lang->title: " . $title . "<br /><br />$owl_lang->description: $desc <br /><br />"; 1029 $mail->Body .= $owl_lang->owl_path . $path . "/" . $filename; 1030 $mail->Body .= "<br /><br />" . $owl_lang->notif_user . " " .uid_to_name($userid); 1031 //$mail->altBody = "URL: $newfilename \n\n$owl_lang->notif_msg_alt\n\n" . "$owl_lang->title: $title" . "\n\n $owl_lang->description: $desc\n\n"; 1032 //$mail->altBody .= $owl_lang->owl_path . $path . "/" . $filename; 1033 } 1034 } 1035 else 1036 { 1037 $mail = new phpmailer(); 1038 if ($default->use_smtp) 1039 { 1040 $mail->IsSMTP(); // set mailer to use SMTP 1041 if ($default->use_smtp_auth) 1042 { 1043 $mail->SMTPAuth = "true"; // turn on SMTP authentication 1044 $mail->Username = "$default->smtp_auth_login "; // SMTP username 1045 $mail->Password = "$default->smtp_passwd"; // SMTP password 1046 } 1047 } 1048 $mail->CharSet = "$owl_lang->charset"; // set the email charset to the language file charset 1049 $mail->Host = "$default->owl_email_server"; // specify main and backup server 1050 $mail->From = "$default->owl_email_from"; 1051 $mail->FromName = "$default->owl_email_fromname"; 1052 $mail->AddAddress($email); 1053 $mail->AddReplyTo("$default->owl_email_replyto", "OWL Intranet"); 1054 $mail->WordWrap = 50; // set word wrap to 50 characters 1055 $mail->IsHTML(true); // set email format to HTML 1056 $mail->Subject = "$default->owl_email_subject $owl_lang->notif_subject_upd"; 1057 if ($type != "url") 1058 { 1059 if ($sql->f("attachfile") == 1) 1060 { 1061 $mail->Body = "<html><body>" . "$owl_lang->notif_msg<br /><br />" . "$owl_lang->title: $title" . "<br /><br />$owl_lang->description: $desc<br /><br />"; 1062 $mail->Body .= $owl_lang->owl_path . $path . "/" . $filename; 1063 $mail->Body .= "<br /><br />" . $owl_lang->notif_user . " " .uid_to_name($userid); 1064 //$mail->altBody = "$owl_lang->notif_msg_alt\n\n" . "$owl_lang->title: $title" . "\n\n $owl_lang->description: $desc \n\n"; 1065 //$mail->altBody .= $owl_lang->owl_path . $path . "/" . $filename; 1066 if (!$default->owl_use_fs) 1067 { 1068 if (file_exists("$default->owl_FileDir/$filename")) 1069 { 1070 unlink("$default->owl_FileDir/$filename"); 1071 } 1072 $file = fopen("$default->owl_FileDir/$filename", 'wb'); 1073 $getfile = new Owl_DB; 1074 $getfile->query("SELECT data,compressed from $default->owl_files_data_table where id='$fileid'"); 1075 while ($getfile->next_record()) 1076 { 1077 if ($getfile->f("compressed")) 1078 { 1079 $tmpfile = $default->owl_tmpdir . "/owltmp.$fileid.gz"; 1080 $uncomptmpfile = $default->owl_tmpdir . "/owltmp.$fileid"; 1081 if (file_exists($tmpfile)) unlink($tmpfile); 1082 1083 $fp = fopen($tmpfile, "w"); 1084 fwrite($fp, $getfile->f("data")); 1085 fclose($fp); 1086 1087 system($default->gzip_path . " -df $tmpfile"); 1088 1089 $fsize = filesize($uncomptmpfile); 1090 $fd = fopen($uncomptmpfile, 'rb'); 1091 $filedata = fread($fd, $fsize); 1092 fclose($fd); 1093 1094 fwrite($file, $filedata); 1095 unlink($uncomptmpfile); 1096 } 1097 else 1098 { 1099 fwrite($file, $getfile->f("data")); 1100 } 1101 } 1102 fclose($file); 1103 $mimeType = fGetMimeType($newfilename); 1104 $mail->AddAttachment("$default->owl_FileDir/$newfilename", "" , "base64" , "$mimeType"); 1105 } 1106 else 1107 { 1108 $mimeType = fGetMimeType($newfilename); 1109 $mail->AddAttachment("$default->owl_FileDir/$newpath/$newfilename", "" , "base64" , "$mimeType"); 1110 } 1111 } 1112 else 1113 { 1114 $link = $default->owl_notify_link . "browse.php?sess=$tempsess&parent=$parent&expand=1&fileid=$fileid"; 1115 $mail->Body = "<html><body>" . "$owl_lang->notif_msg_link<br /><br />" . "$owl_lang->title: " . $title . "<br /><br />URL: <A HREF=" . $link . ">" . $link . "</A><br /><br />$owl_lang->description: $desc <br /><br />"; 1116 $mail->Body .= $owl_lang->owl_path . $path . "/" . $filename; 1117 $mail->Body .= "<br /><br />" . $owl_lang->notif_user . " " .uid_to_name($userid); 1118 //$mail->altBody = "$owl_lang->notif_msg_alt\n\n" . "$owl_lang->title: $title" . "\n\n $owl_lang->description: $desc \n\n"; 1119 //$mail->altBody .= $owl_lang->owl_path . $path . "/" . $filename; 1120 } 1121 } 1122 else 1123 { 1124 $mail->Body = "<html><body>" . "URL: <A HREF=" . $newfilename . ">" . $newfilename . "</A> <br /><br />$owl_lang->notif_msg_link<br /><br />" . "$owl_lang->title: " . $title . "<br /><br />$owl_lang->description: $desc <br /><br />"; 1125 $mail->Body .= $owl_lang->owl_path . $path . "/" . $filename; 1126 $mail->Body .= "<br /><br />" . $owl_lang->notif_user . " " .uid_to_name($userid); 1127 //$mail->altBody = "URL: $newfilename \n\n$owl_lang->notif_msg_alt\n\n" . "$owl_lang->title: $title" . "\n\n $owl_lang->description: $desc \n\n"; 1128 //$mail->altBody .= $owl_lang->owl_path . $path . "/" . $filename; 1129 } 1130 } 1131 $mail->Body .= "</body></html>"; 1132 1133 if (!$mail->Send() && $default->debug == true) 1134 { 1135 printError("DEBUG: " . $owl_lang->err_email, $mail->ErrorInfo); 1136 } 1137 1138 if (!$default->owl_use_fs && $sql->f("attachfile") == 1) 1139 { 1140 if ($type == "") 1141 { 1142 unlink("$default->owl_FileDir/$newfilename"); 1143 } 1144 } 1145 } 1146 } 1147 } 1148 } 1149 1150 function fInsertUnzipedFiles($path, $cParent, $FolderPolicy, $FilePolicy, $description, $groupid, $userid, $metadata, $title, $major_revision, $minor_revision, $doctype) 1151 { 1152 global $default, $userid; 1153 $sql = new OWL_DB; 1154 $sql_custom = new OWL_DB; 1155 1156 $dir = dir($path); 1157 $dir->rewind(); 1158 1159 while (false !== ($file = $dir->read())) 1160 //while ($file = $dir->read()) 1161 { 1162 if ($file != "." and $file != ".." and $file != "CVS") 1163 { 1164 if(is_dir($path . "/" . $file)) 1165 { 1166 1167 $original_name = $file; 1168 $file = trim(ereg_replace("[^$default->list_of_valid_chars_in_file_names]", "", ereg_replace("%20|^-", "_", $file))); 1169 if($original_name != $file) 1170 { 1171 rename($path. "/" . $original_name,$path . "/" . $file); 1172 } 1173 $smodified = $sql->now(); 1174 $sql->query("INSERT into $default->owl_folders_table (name,parent,security,description,groupid,creatorid,smodified) values ('$file', '$cParent', '$FolderPolicy', '$description', '$groupid', '$userid', $smodified)"); 1175 1176 $newParent = $sql->insert_id($default->owl_folders_table, 'id'); 1177 1178 fInsertUnzipedFiles($path . "/" .$file, $newParent, $FolderPolicy, $FilePolicy, $description, $groupid, $userid, $metadata, $title, $major_revision, $minor_revision, $doctype); 1179 } 1180 else 1181 { 1182 $TheFileSize = filesize($path . "/" . $file); //get filesize 1183 $TheFileTime = date("Y-m-d H:i:s", filemtime($path . "/" . $file)); 1184 1185 $original_name = $file; 1186 $file = trim(ereg_replace("[^$default->list_of_valid_chars_in_file_names]", "", ereg_replace("%20|^-", "_", $file))); 1187 if($original_name != $file) 1188 { 1189 rename($path. "/" . $original_name,$path . "/" . $file); 1190 } 1191 1192 if ($title == "") 1193 { 1194 $ctitle = $file; 1195 } 1196 else 1197 { 1198 $ctitle = $title; 1199 } 1200 $ctitle = stripslashes($ctitle); 1201 $ctitle = ereg_replace("'", "\\'" , ereg_replace("[<>]", "", $ctitle)); 1202 1203 $new_quota = fCalculateQuota($TheFileSize, $userid, "ADD"); 1204 1205 $result = $sql->query("INSERT INTO $default->owl_files_table (name,filename,f_size,creatorid,parent,created,description,metadata,security,groupid,smodified,checked_out, major_revision, minor_revision, url, doctype, approved) values ('$ctitle', '$file', '$TheFileSize', '$userid', '$cParent', '$TheFileTime' , '$description', '$metadata', '$FilePolicy', '$groupid', '$TheFileTime', '0','$major_revision','$minor_revision', '0', '$doctype', '1')"); 1206 1207 if ( fIsQuotaEnabled($userid) ) 1208 { 1209 $sql->query("UPDATE $default->owl_users_table set quota_current = '$new_quota' where id = '$userid'"); 1210 } 1211 1212 $searchid = $sql->insert_id($default->owl_files_table, 'id'); 1213 1214 //***************************************************** 1215 // This line was commented out because on large 1216 // Zip files with allot of indexable files 1217 // it would cause the Script to time out and/or run out of resources. 1218 // Run admin/tools/bigindex.pl instead. 1219 // 1171872 Error in "Add Archive" 1220 //***************************************************** 1221 if ($default->index_files_on_archive_add == 1) 1222 { 1223 fIndexAFile($file, $path . "/" . $file, $searchid); 1224 } 1225 1226 $sql_custom->query("SELECT * from $default->owl_docfields_table where doc_type_id = '$doctype'"); 1227 while ($sql_custom->next_record()) 1228 { 1229 $result = $sql->query("INSERT INTO $default->owl_docfieldvalues_table (file_id, field_name, field_value) values ('$searchid', '" . $sql_custom->f("field_name") ."', '" . ${$sql_custom->f("field_name")} ."');"); 1230 } 1231 if ( !$default->owl_use_fs ) 1232 { 1233 if ($default->owl_compressed_database && file_exists($default->gzip_path)) 1234 { 1235 system($default->gzip_path . " " . escapeshellarg($zipedfile)); 1236 $zipedfile = $path . "/" . $file . ".gz"; 1237 $fsize = filesize($zipedfile); 1238 $compressed = '1'; 1239 } 1240 else 1241 { 1242 $zipedfile = $path . "/" . $file; 1243 $fsize = filesize($zipedfile); 1244 } 1245 1246 $fd = fopen($zipedfile, 'rb'); 1247 $filedata = fread($fd, $fsize); 1248 fclose($fd); 1249 unlink($zipedfile); 1250 1251 if ($searchid !== null && $filedata) 1252 { 1253 $sql->query("INSERT into $default->owl_files_data_table (id, data, compressed) values ('$searchid', '" . addslashes($filedata) ."', '$compressed')"); 1254 } 1255 1256 } 1257 } 1258 } 1259 } 1260 $dir->close(); 1261 } 1262 1263 1264 function fVirusCheck($filename, $name) 1265 { 1266 global $default, $userid, $parent, $owl_lang; 1267 1268 //if ( file_exists($default->virus_path)) 1269 if (trim($default->virus_path) <> "") 1270 { 1271 system($default->virus_path . " " . $filename, $retval); 1272 if ($retval > 0) 1273 { 1274 owl_syslog(FILE_VIRUS, $userid, $name, $parent, $owl_lang->log_detail, "FILE"); 1275 if ($default->debug == true) 1276 { 1277 printError("DEBUG: $owl_lang->virus_infected -- $filename" , "DEBUG: $owl_lang->virus_return_val " . $retval); 1278 } 1279 else 1280 { 1281 printError($owl_lang->virus_infected); 1282 } 1283 } 1284 } 1285 } 1286 1287 function verify_login($username, $password) 1288 { 1289 global $default; 1290 $sql = new Owl_DB; 1291 1292 1293 if ($username == "admin" and $default->auth > 1) 1294 { 1295 $default->auth = 0; 1296 } 1297 1298 if ( $default->auth == 1) 1299 { 1300 $username = addslashes($username); 1301 $password = addslashes($password); 1302 $sql->query("SELECT * from $default->owl_users_table where username = '$username'"); 1303 } 1304 else if ( $default->auth == 2) 1305 { 1306 $mbox = @imap_open ("{" . $default->auth_host . "/pop3/notls:" . $default->auth_port . "}INBOX", $username, $password); 1307 if($mbox) 1308 { 1309 $username = addslashes($username); 1310 $sql->query("SELECT * from $default->owl_users_table where username = '$username'"); 1311 imap_close($mbox); 1312 } 1313 else 1314 { 1315 $sql->query("SELECT * from $default->owl_users_table where username = 'junkusernamethatwillneverbeused'"); 1316 } 1317 } 1318 else if ( $default->auth == 3) 1319 { 1320 // LDAP - authenticate the user and if successful get his details from owl db 1321 // then if he's not in the owl db, login wil fail... 1322 $error = ldap_authenticate($username, $password); 1323 if ($error == "0") 1324 { 1325 $sql->query("SELECT * from $default->owl_users_table where username = '$username'"); 1326 } 1327 else 1328 { 1329 $sql->query("SELECT * from $default->owl_users_table where username = 'junkusernamethatwillneverbeused'"); 1330 } 1331 } 1332 else 1333 { 1334 $username = addslashes($username); 1335 $password = addslashes($password); 1336 $sql->query("SELECT * from $default->owl_users_table where username = '$username' and password = '" . md5($password) . "'"); 1337 } 1338 1339 $numrows = $sql->num_rows($sql); 1340 1341 // Bozz Begin added Password Encryption above, but for now 1342 // I will allow admin to use non crypted password until he 1343 // upgrades all users 1344 if ($numrows == "1") 1345 { 1346 //while ($sql->next_record()) 1347 $sql->next_record(); 1348 //{ 1349 $iFirstDir = $sql->f("firstdir"); 1350 $iHomeDir = $sql->f("homedir"); 1351 $iMaxSession = $sql->f("maxsessions"); 1352 1353 if ($sql->f("disabled") == 1) 1354 { 1355 $verified["bit"] = 2; 1356 } 1357 else 1358 { 1359 $verified["bit"] = 1; 1360 } 1361 $verified["user"] = $sql->f("username"); 1362 $verified["uid"] = $sql->f("id"); 1363 $verified["group"] = $sql->f("groupid"); 1364 if ( $iHomeDir <> $iFirstDir) 1365 { 1366 $sql->query("SELECT * from $default->owl_folders_table where id = '$iFirstDir'"); 1367 $numrows = $sql->num_rows($sql); 1368 if ($numrows == "1") 1369 { 1370 $verified["homedir"] = $iFirstDir; 1371 } 1372 else 1373 { 1374 $verified["homedir"] = $iHomeDir; 1375 } 1376 } 1377 else 1378 { 1379 $verified["homedir"] = $iHomeDir; 1380 } 1381 $maxsessions = $iMaxSession + 1; 1382 //} 1383 } 1384 else 1385 { 1386 // LOGIN has FAILED, lets see if a valid username has been used 1387 // 1388 $sql->query("SELECT * from $default->owl_users_table where username = '$username'"); 1389 $numrows = $sql->num_rows($sql); 1390 if ($numrows == "1") 1391 { 1392 while ($sql->next_record()) 1393 { 1394 $verified["uid"] = $sql->f("id"); 1395 $verified["user"] = $sql->f("username"); 1396 } 1397 } 1398 else 1399 { 1400 if ($default->auth == 1) 1401 { 1402 die("ACCESS DENIED"); 1403 exit; 1404 } 1405 } 1406 1407 } 1408 // remove stale sessions from the database for the user 1409 // that is signing on. 1410 1411 $time = time() - $default->owl_timeout; 1412 if ($verified["group"] == 0) 1413 { 1414 $sql = new Owl_DB; 1415 $sql->query("DELETE from $default->owl_sessions_table where lastused <= $time "); 1416 } 1417 else 1418 { 1419 $sql = new Owl_DB; 1420 $sql->query("DELETE from $default->owl_sessions_table where usid = '" . $verified["uid"] . "' and lastused <= $time "); 1421 } 1422 // Check if Maxsessions has been reached 1423 1424 $sql = new Owl_DB; 1425 $sql->query("SELECT * from $default->owl_sessions_table where ip <> '0' and usid = '" . $verified["uid"] . "'"); 1426 1427 if ($sql->num_rows($sql) >= $maxsessions && $verified["bit"] != 0) 1428 { 1429 if ($verified["group"] == 0) 1430 { 1431 $verified["bit"] = 1; 1432 } 1433 else 1434 { 1435 $verified["bit"] = 3; 1436 } 1437 } 1438 return $verified; 1439 } 1440 1441 function verify_session($sess) 1442 { 1443 global $default; 1444 global $owl_lang; 1445 global $parent, $fileid; 1446 1447 $sess = ltrim($sess); 1448 $verified["bit"] = 0; 1449 $sql = new Owl_DB; 1450 $sql->query("SELECT * from $default->owl_sessions_table where sessid = '$sess'"); 1451 $numrows = $sql->num_rows($sql); 1452 $time = time(); 1453 if ($numrows == "1") 1454 { 1455 while ($sql->next_record()) 1456 { 1457 if (getenv("HTTP_CLIENT_IP")) 1458 { 1459 $ip = getenv("HTTP_CLIENT_IP"); 1460 } elseif (getenv("HTTP_X_FORWARDED_FOR")) 1461 { 1462 $forwardedip = getenv("HTTP_X_FORWARDED_FOR"); 1463 list($ip, $ip2, $ip3, $ip4) = split (",", $forwardedip); 1464 } 1465 else 1466 { 1467 $ip = getenv("REMOTE_ADDR"); 1468 } 1469 if ($ip == $sql->f("ip") || 0 == $sql->f("ip")) 1470 { 1471 if (($time - $sql->f("lastused")) <= $default->owl_timeout) 1472 { 1473 $verified["bit"] = 1; 1474 $verified["userid"] = $sql->f("usid"); 1475 $verified["currentdb"] = $sql->f("currentdb"); 1476 $sql->query("SELECT * from $default->owl_users_table where id = '" . $verified["userid"] . "'"); 1477 while ($sql->next_record()) $verified["groupid"] = $sql->f("groupid"); 1478 } 1479 else 1480 { 1481 if ($default->remember_me) 1482 { 1483 setcookie ("owl_sessid", ""); 1484 } 1485 if (file_exists("./lib/header.inc")) 1486 { 1487 include_once ("./lib/header.inc"); 1488 include_once ("./lib/userheader.inc"); 1489 } 1490 else 1491 { 1492 if (file_exists("../lib/header.inc")) 1493 { 1494 include_once ("../lib/header.inc"); 1495 include_once ("../lib/userheader.inc"); 1496 } 1497 else 1498 { 1499 include_once("../../lib/header.inc"); 1500 include_once("../../lib/userheader.inc"); 1501 } 1502 } 1503 print("<center>"); 1504 print("<table class='border1' cellspacing='0' cellpadding='0' border='0' width='$default->table_collapse_width'><tr><td align='left' valign='top' width='100%'>\n"); 1505 fPrintButtonSpace(12, 1); 1506 print("<br />\n"); 1507 print("<table class='border2' cellspacing='0' cellpadding='0' border='0' width='100%'><tr><td align='left' valign='top' width='100%'>\n"); 1508 1509 if ($default->show_prefs == 1 or $default->show_prefs == 3) 1510 { 1511 fPrintPrefs(); 1512 } 1513 1514 fPrintButtonSpace(12, 1); 1515 print("<br />\n"); 1516 print("<table class='margin2' cellspacing='0' cellpadding='0' border='0' width='100%'>\n"); 1517 print("<tr>\n"); 1518 print("<td align='left' valign='top'>\n"); 1519 print("<table cellspacing='0' cellpadding='0' border='0' width='100%'>\n"); 1520 fPrintFormTextLine(" ", "", "", $owl_lang->sesstimeout , "", true); 1521 print("<tr>"); 1522 print("<td class='form1'>"); 1523 fPrintButtonSpace(1, 1); 1524 print("</td>"); 1525 print("<td>"); 1526 print("<table class='border1' cellspacing='0' cellpadding='0' border='0' width='100%'>"); 1527 print("<tr><td valign='top' width='100%'>"); 1528 fPrintButtonSpace(1, 1); 1529 print("</td>"); 1530 if ($parent == "" || $fileid == "") 1531 { 1532 fPrintButton("$default->owl_root_url/index.php", "btn_login"); 1533 } 1534 else 1535 { 1536 fPrintButton("$default->owl_root_url/index.php?parent=$parent&fileid=$fileid", "btn_login"); 1537 } 1538 //print("\t\t<td class='button1' background='$default->owl_graphics_url/$default->sButtonStyle/ui_misc/button1_fill.jpg'>"); 1539 print("\t\t<td class='button1'>"); 1540 print("<input class='fbuttonup1' type='submit' value='$owl_lang->btn_back' alt='$owl_lang->alt_back' title='$owl_lang->alt_back' onclick='history.back();' onmouseover=\"highlightButton('fbuttondown1')\" onmouseout=\"highlightButton('fbuttonup1')\"></input>"); 1541 print("</td>"); 1542 print("</tr></table>\n"); 1543 1544 print("</td></tr>"); 1545 print("</table>\n"); 1546 fPrintButtonSpace(12, 1); 1547 print("<br />\n"); 1548 print("</td></tr></table>\n"); 1549 1550 fPrintButtonSpace(12, 1); 1551 1552 if ($default->show_prefs == 2 or $default->show_prefs == 3) 1553 { 1554 fPrintPrefs(); 1555 } 1556 print("</td></tr></table>\n"); 1557 if (file_exists("./lib/footer.inc")) 1558 { 1559 include ("./lib/footer.inc"); 1560 } 1561 else 1562 { 1563 if (file_exists("../lib/footer.inc")) 1564 { 1565 include ("../lib/footer.inc"); 1566 } 1567 else 1568 { 1569 include("../../lib/footer.inc"); 1570 } 1571 } 1572 //print("</td></tr></table>\n"); 1573 exit(); 1574 } 1575 } 1576 else 1577 { 1578 if (file_exists("./lib/header.inc")) 1579 { 1580 include ("./lib/header.inc"); 1581 include ("./lib/userheader.inc"); 1582 } 1583 else 1584 { 1585 include ("../lib/header.inc"); 1586 include ("../lib/userheader.inc"); 1587 } 1588 print("<br /><br /><center>" . $owl_lang->sessinuse); 1589 if ($parent == "" || $fileid == "") 1590 { 1591 fPrintButton("$default->owl_root_url/index.php", "btn_login"); 1592 } 1593 else 1594 { 1595 fPrintButton("$default->owl_root_url/index.php?parent=$parent&fileid=$fileid", "btn_login"); 1596 } 1597 if (file_exists("./lib/footer.inc")) 1598 { 1599 include ("./lib/footer.inc"); 1600 } 1601 else 1602 { 1603 include ("../lib/footer.inc"); 1604 } 1605 exit; 1606 } 1607 } 1608 } 1609 return $verified; 1610 } 1611 1612 function delTree($fid) 1613 { 1614 global $fCount, $folderList, $default; 1615 // delete from database 1616 $sql = new Owl_DB; 1617 $del = new Owl_DB; 1618 $sql->query("DELETE from $default->owl_folders_table where id = '$fid'"); 1619 $sql->query("DELETE from $default->owl_monitored_folder_table where fid = '$fid'"); 1620 1621 $sql->query("SELECT id from $default->owl_files_table where parent = '$fid'"); 1622 // Clean up Comments and Monitored Files from each file we are going to 1623 // delete 1624 while ($sql->next_record()) 1625 { 1626 $iFileid = $sql->f("id"); 1627 $del->query("DELETE from $default->owl_monitored_file_table where fid = '$iFileid'"); 1628 $del->query("DELETE from $default->owl_comment_table where fid = '$iFileid'"); 1629 if (!$default->owl_use_fs) 1630 { 1631 $del->query("DELETE from $default->owl_files_data_table where id = '$iFileid'"); 1632 } 1633 // Clean up all comments with this file 1634 $del->query("DELETE from $default->owl_docfieldvalues_table WHERE file_id = '$iFileid'"); 1635 // Clean up all linked files 1636 $del->query("DELETE from $default->owl_files_table WHERE linkedto = '$iFileid'"); 1637 // Clean up all linked files 1638 $del->query("DELETE from $default->owl_peerreview_table WHERE file_id = '$iFileid'"); 1639 // Clean Up SEARCH Indexes for this file 1640 fDeleteFileIndexID($iFileid); 1641 } 1642 $sql->query("DELETE from $default->owl_files_table where parent = '$fid'"); 1643 1644 for ($c = 0; $c < $fCount; $c++) 1645 { 1646 if ($folderList[$c][2] == $fid) 1647 { 1648 delTree($folderList[$c][0]); 1649 } 1650 } 1651 } 1652 1653 function find_path($parent) 1654 { 1655 global $default; 1656 $path = fid_to_name($parent); 1657 $sql = new Owl_DB; 1658 while ($parent != 1) 1659 { 1660 $sql->query("SELECT parent from $default->owl_folders_table where id = '$parent'"); 1661 while ($sql->next_record()) 1662 { 1663 $path = fid_to_name($sql->f("parent")) . "/" . $path; 1664 $parent = $sql->f("parent"); 1665 } 1666 } 1667 return $path; 1668 } 1669 1670 function fid_to_filename($id) 1671 { 1672 global $default; 1673 $sql = new Owl_DB; 1674 $sql->query("SELECT filename from $default->owl_files_table where id = '$id'"); 1675 while ($sql->next_record()) return $sql->f("filename"); 1676 } 1677 1678 function fid_to_name($parent) 1679 { 1680 global $default; 1681 $sql = new Owl_DB; 1682 if (empty($parent)) 1683 { 1684 $parent=0; 1685 } 1686 $sql->query("SELECT name from $default->owl_folders_table where id = '$parent'"); 1687 while ($sql->next_record()) 1688 { 1689 return $sql->f("name"); 1690 } 1691 } 1692 1693 function flid_to_name($id) 1694 { 1695 global $default; 1696 $sql = new Owl_DB; 1697 $sql->query("SELECT name from $default->owl_files_table where id = '$id'"); 1698 while ($sql->next_record()) return $sql->f("name"); 1699 } 1700 1701 function flid_to_filename($id) 1702 { 1703 global $default; 1704 $sql = new Owl_DB; 1705 $sql->query("SELECT filename from $default->owl_files_table where id = '$id'"); 1706 while ($sql->next_record()) return $sql->f("filename"); 1707 } 1708 1709 function owlusergroup($userid) 1710 { 1711 global $default; 1712 $sql = new Owl_DB; 1713 $sql->query("SELECT groupid from $default->owl_users_table where id = '$userid'"); 1714 while ($sql->next_record()) $groupid = $sql->f("groupid"); 1715 return $groupid; 1716 } 1717 1718 function owlfilecreator($fileid) 1719 { 1720 global $default; 1721 $filecreator = 0; 1722 $sql = new Owl_DB; 1723 $sql->query("SELECT creatorid from " . $default->owl_files_table . " where id = '$fileid'"); 1724 while ($sql->next_record()) $filecreator = $sql->f("creatorid"); 1725 return $filecreator; 1726 } 1727 1728 1729 function uid_to_lastlogon($creatorid) 1730 { 1731 global $default, $owl_lang; 1732 1733 $sql2 = new Owl_DB; 1734 $sql2->query("SELECT lastlogin from $default->owl_users_table where id = '" . $creatorid . "'"); 1735 $sql2->next_record(); 1736 if ( $sql2->num_rows() == 0 ) 1737 { 1738 $logindate = 0; 1739 } 1740 else 1741 { 1742 $logindate = $sql2->f("lastlogin"); 1743 } 1744 return $logindate; 1745 } 1746 1747 1748 function fid_to_creator_lastlogon($id) 1749 { 1750 global $default, $owl_lang; 1751 1752 $sql2 = new Owl_DB; 1753 $creatorid = owlfilecreator($id); 1754 $sql2->query("SELECT lastlogin from $default->owl_users_table where id = '" . $creatorid . "'"); 1755 $sql2->next_record(); 1756 if ( $sql2->num_rows() == 0 ) 1757 { 1758 $logindate = 0; 1759 } 1760 else 1761 { 1762 $logindate = $sql2->f("lastlogin"); 1763 } 1764 return $logindate; 1765 } 1766 1767 function fid_to_creator($id) 1768 { 1769 global $default, $owl_lang; 1770 1771 $sql2 = new Owl_DB; 1772 $creatorid = owlfilecreator($id); 1773 $sql2->query("SELECT name from $default->owl_users_table where id = '" . $creatorid . "'"); 1774 $sql2->next_record(); 1775 if ( $sql2->num_rows() == 0 ) 1776 { 1777 $name = "<font class=\"url\">" . $owl_lang->orphaned . "</font>"; 1778 } 1779 else 1780 { 1781 $name = $sql2->f("name"); 1782 } 1783 return $name; 1784 } 1785 1786 function owlfoldercreator($folderid) 1787 { 1788 global $default; 1789 $foldercreator = 0; 1790 $sql = new Owl_DB; 1791 $sql->query("SELECT creatorid from " . $default->owl_folders_table . " where id = '$folderid'"); 1792 while ($sql->next_record()) $foldercreator = $sql->f("creatorid"); 1793 return $foldercreator; 1794 } 1795 1796 function flid_to_creator($folderid) 1797 { 1798 global $default, $owl_lang; 1799 //$sql = new Owl_DB; 1800 //$sql->query("SELECT creatorid from " . $default->owl_files_table . " where id = '$id'"); 1801 $sql2 = new Owl_DB; 1802 //while ($sql->next_record()) 1803 //{ 1804 //$creatorid = $sql->f("creatorid"); 1805 $creatorid = owlfoldercreator($folderid); 1806 $sql2->query("SELECT name from $default->owl_users_table where id = '" . $creatorid . "'"); 1807 $sql2->next_record(); 1808 if ( $sql2->num_rows() == 0 ) 1809 { 1810 $name = "<font class=url>" . $owl_lang->orphaned . "</font>"; 1811 } 1812 else 1813 { 1814 $name = $sql2->f("name"); 1815 } 1816 //} 1817 return $name; 1818 } 1819 1820 function owlfiletype ($fileid) 1821 { 1822 global $default; 1823 $filecreator = 0; 1824 $sql = new Owl_DB; 1825 $sql->query("SELECT url from " . $default->owl_files_table . " where id = '$fileid'"); 1826 while ($sql->next_record()) $filetype = $sql->f("url"); 1827 return $filetype; 1828 } 1829 function owlfilegroup($fileid) 1830 { 1831 global $default; 1832 $filegroup = 0; 1833 $sql = new Owl_DB; 1834 $sql->query("SELECT groupid from $default->owl_files_table where id = '$fileid'"); 1835 while ($sql->next_record()) $filegroup = $sql->f("groupid"); 1836 return $filegroup; 1837 } 1838 1839 function owlfoldergroup($folderid) 1840 { 1841 global $default; 1842 $foldergroup = 0; 1843 $sql = new Owl_DB; 1844 $sql->query("SELECT groupid from $default->owl_folders_table where id = '$folderid'"); 1845 while ($sql->next_record()) $foldergroup = $sql->f("groupid"); 1846 return $foldergroup; 1847 } 1848 1849 1850 function fCurFolderSecurity($folderid) 1851 { 1852 global $default; 1853 1854 $sql = new Owl_DB; 1855 $sql->query("SELECT security from $default->owl_folders_table where id = '$folderid'"); 1856 while ($sql->next_record()) 1857 { 1858 $iFoldSecurity = $sql->f("security"); 1859 } 1860 return $iFoldSecurity; 1861 } 1862 1863 function owlfolderparent($folderid) 1864 { 1865 global $default; 1866 1867 if ( $default->HomeDir == $folderid ) 1868 { 1869 $folderparent = 1; 1870 } 1871 else 1872 { 1873 $sql = new Owl_DB; 1874 $sql->query("SELECT parent from $default->owl_folders_table where id = '$folderid'"); 1875 while ($sql->next_record()) 1876 { 1877 $folderparent = $sql->f("parent"); 1878 } 1879 } 1880 return $folderparent; 1881 } 1882 1883 1884 1885 function owlfileparent($fileid) 1886 { 1887 global $default; 1888 $sql = new Owl_DB; 1889 $sql->query("SELECT parent from $default->owl_files_table where id = '$fileid'"); 1890 while ($sql->next_record()) $fileparent = $sql->f("parent"); 1891 return $fileparent; 1892 } 1893 1894 1895 function group_to_name($id) 1896 { 1897 global $default; 1898 $sql = new Owl_DB; 1899 $sql->query("SELECT name from $default->owl_groups_table where id = '$id'"); 1900 while ($sql->next_record()) return $sql->f("name"); 1901 } 1902 1903 function uid_to_name($id) 1904 { 1905 global $default; 1906 $name = ""; 1907 $sql = new Owl_DB; 1908 $sql->query("SELECT name from $default->owl_users_table where id = '$id'"); 1909 while ($sql->next_record()) $name = $sql->f("name"); 1910 if ($name == "") $name = "Owl"; 1911 return $name; 1912 } 1913 1914 function uid_to_uname($id) 1915 { 1916 global $default; 1917 $name = ""; 1918 $sql = new Owl_DB; 1919 $sql->query("SELECT username from $default->owl_users_table where id = '$id'"); 1920 while ($sql->next_record()) $username = $sql->f("username"); 1921 if ($username == "") $username = "Owl"; 1922 return $username; 1923 } 1924 1925 function prefaccess($id) 1926 { 1927 global $default; 1928 $prefaccess = 1; 1929 $sql = new Owl_DB; 1930 $sql->query("SELECT noprefaccess from $default->owl_users_table where id = '$id'"); 1931 while ($sql->next_record()) $prefaccess = !($sql->f("noprefaccess")); 1932 return $prefaccess; 1933 } 1934 // only get dir path from db 1935 function get_dirpath($parent) 1936 { 1937 global $default; 1938 global $sess, $expand; 1939 $name = fid_to_name($parent); 1940 $navbar = "$name"; 1941 $new = $parent; 1942 while ($new != "1") 1943 { 1944 $sql = new Owl_DB; 1945 $sql->query("SELECT parent from $default->owl_folders_table where id = '$new'"); 1946 while ($sql->next_record()) $newparentid = $sql->f("parent"); 1947 if ($newparentid == "") break; 1948 $name = fid_to_name($newparentid); 1949 $navbar = "$name/" . $navbar; 1950 $new = $newparentid; 1951 } 1952 return $navbar; 1953 } 1954 1955 function get_dirpathfs($parent) 1956 { 1957 global $default; 1958 global $sess, $expand; 1959 $name = fid_to_name($parent); 1960 $navbar = "$name"; 1961 $new = $parent; 1962 while ($new != "1") 1963 { 1964 $sql = new Owl_DB; 1965 $sql->query("SELECT parent from $default->owl_folders_table where id = '$new'"); 1966 while ($sql->next_record()) $newparentid = $sql->f("parent"); 1967 if ($newparentid == "") break; 1968 $name = fid_to_name($newparentid); 1969 $navbar = "$name\\" . $navbar; 1970 $new = $newparentid; 1971 } 1972 return $navbar; 1973 } 1974 1975 function fIsAdmin($Admin = false) 1976 { 1977 global $default, $usergroupid, $userid; 1978 1979 if (empty($userid)) 1980 { 1981 $userid = 0; 1982 } 1983 1984 if($Admin) 1985 { 1986 if ($usergroupid == "0") 1987 { 1988 return true; 1989 } 1990 else 1991 { 1992 $sql = new Owl_DB; 1993 $sql->query("SELECT userid,groupid from $default->owl_users_grpmem_table where userid = '$userid' and groupid = '0'"); 1994 1995 if ($sql->num_rows($sql) == 0) 1996 { 1997 return false; 1998 } 1999 else 2000 { 2001 return true; 2002 } 2003 } 2004 } 2005 else 2006 { 2007 if ($usergroupid == "0" or $usergroupid == $default->file_admin_group) 2008 { 2009 return true; 2010 } 2011 else 2012 { 2013 $sql = new Owl_DB; 2014 $sql->query("SELECT userid,groupid from $default->owl_users_grpmem_table where userid = '$userid' and (groupid = '$default->file_admin_group' or groupid = '0')"); 2015 2016 if ($sql->num_rows($sql) == 0) 2017 { 2018 return false; 2019 } 2020 else 2021 { 2022 return true; 2023 } 2024 } 2025 } 2026 return false; 2027 } 2028 2029 function fIsEmailToolAccess($userid) 2030 { 2031 global $default; 2032 2033 $sql = new Owl_DB; 2034 $sql->query("SELECT email_tool from $default->owl_users_table where id = '$userid'"); 2035 $sql->next_record(); 2036 if ($sql->f("email_tool") == 1) 2037 { 2038 return true; 2039 } 2040 return false; 2041 } 2042 2043 function fIsNewsAdmin($userid) 2044 { 2045 global $default; 2046 2047 $sql = new Owl_DB; 2048 $sql->query("SELECT newsadmin from $default->owl_users_table where id = '$userid'"); 2049 $sql->next_record(); 2050 if ($sql->f("newsadmin") == 1) 2051 { 2052 return true; 2053 } 2054 return false; 2055 } 2056 2057 function gen_filesize($file_size) 2058 { 2059 global $owl_lang; 2060 2061 if (ereg("[^0-9]", $file_size)) return $file_size; 2062 2063 if ($file_size >= 1073741824) 2064 { 2065 $file_size = round($file_size / 1073741824 * 100) / 100 . $owl_lang->file_size_gigabyte; 2066 } elseif ($file_size >= 1048576) 2067 { 2068 $file_size = round($file_size / 1048576 * 100) / 100 . $owl_lang->file_size_megabyte; 2069 } elseif ($file_size >= 1024) 2070 { 2071 $file_size = round($file_size / 1024 * 100) / 100 . $owl_lang->file_size_kilobyte; 2072 } 2073 else 2074 { 2075 if(!empty($file_size)) 2076 { 2077 $file_size = $file_size . $owl_lang->file_size_byte; 2078 } 2079 else 2080 { 2081 $file_size = "0". $owl_lang->file_size_byte; 2082 } 2083 } 2084 return $file_size; 2085 } 2086 2087 function uploadCompat($varname) 2088 { 2089 global $HTTP_POST_FILES; 2090 2091 if ($_FILES[$varname]) return $_FILES[$varname]; 2092 if ($HTTP_POST_FILES[$varname]) return $HTTP_POST_FILES[$varname]; 2093 $tmp = "$varname_name"; 2094 global $$tmp; 2095 $retfile['name'] = $$tmp; 2096 $tmp = "$varname_type"; 2097 global $$tmp; 2098 $retfile['type'] = $$tmp; 2099 $tmp = "$varname_size"; 2100 global $$tmp; 2101 $retfile['size'] = $$tmp; 2102 $tmp = "$varname_error"; 2103 global $$tmp; 2104 $retfile['error'] = $$tmp; 2105 $tmp = "$varname_tmp_name"; 2106 global $$tmp; 2107 $retfile['tmp_name'] = $$tmp; 2108 return $retfile; 2109 } 2110 2111 function fGetMimeType ($filename) 2112 { 2113 global $default; 2114 2115 $mimeType = "application/octet-stream"; 2116 2117 if ($filetype = strrchr($filename, ".")) 2118 { 2119 $filetype = substr($filetype, 1); 2120 $sql = new Owl_DB; 2121 $sql->query("SELECT * from $default->owl_mime_table where filetype = '$filetype'"); 2122 while ($sql->next_record()) $mimeType = $sql->f("mimetype"); 2123 } 2124 return $mimeType; 2125 } 2126 2127 if ($sess) 2128 { 2129 $ok = verify_session($sess); 2130 $temporary_ok = $ok["bit"]; 2131 $userid = $ok["userid"]; 2132 $default->owl_current_db = $ok["currentdb"]; 2133 $default->owl_FileDir = $default->owl_db_FileDir[$default->owl_current_db]; 2134 getuserprefs(); 2135 gethtmlprefs(); 2136 $usergroupid = $ok["groupid"]; 2137 if ($ok["bit"] != "1") 2138 { 2139 if ($default->remember_me) 2140 { 2141 setcookie ("owl_sessid", ""); 2142 } 2143 if (file_exists("./lib/header.inc")) 2144 { 2145 include ("./lib/header.inc"); 2146 include ("./lib/userheader.inc"); 2147 } 2148 else 2149 { 2150 include ("../lib/header.inc"); 2151 include ("../lib/userheader.inc"); 2152 } 2153 print("<center>\n"); 2154 if ($expand == 1) 2155 { 2156 print("<table class='border1' cellspacing='0' cellpadding='0' border='0' width='$default->table_expand_width'><tr><td align='left' valign='top' width='100%'>\n"); 2157 } 2158 else 2159 { 2160 print("<table class='border1' cellspacing='0' cellpadding='0' border='0' width='$default->table_collapse_width'><tr><td align='left' valign='top' width='100%'>\n"); 2161 } 2162 fPrintButtonSpace(12, 1); 2163 print("<br />\n"); 2164 print("<table class='border2' cellspacing='0' cellpadding='0' border='0' width='100%'><tr><td align='left' valign='top' width='100%'>\n"); 2165 2166 if ($default->show_prefs == 1 or $default->show_prefs == 3) 2167 { 2168 fPrintPrefs(); 2169 } 2170 2171 fPrintButtonSpace(12, 1); 2172 print("<br />\n"); 2173 print("<table class='margin2' cellspacing='0' cellpadding='0' border='0' width='100%'>\n"); 2174 print("<tr>\n"); 2175 print("<td align='left' valign='top'>\n"); 2176 print("<table cellspacing='0' cellpadding='0' border='0' width='100%'>\n"); 2177 fPrintFormTextLine(" ", "", "", $owl_lang->invalidsess , "", true); 2178 print("<tr>\n"); 2179 print("<td class='form1'>"); 2180 fPrintButtonSpace(1, 1); 2181 print("</td>\n"); 2182 print("<td>\n"); 2183 print("<table class='border1' cellspacing='0' cellpadding='0' border='0' width='100%'>\n"); 2184 print("<tr>\n<td valign='top' width='100%'>"); 2185 fPrintButtonSpace(1, 1); 2186 print("</td>"); 2187 if ($parent == "" || $fileid == "") 2188 { 2189 fPrintButton("$default->owl_root_url/index.php", "btn_login"); 2190 } 2191 else 2192 { 2193 fPrintButton("$default->owl_root_url/index.php?parent=$parent&fileid=$fileid", "btn_login"); 2194 } 2195 //print("\t\t<td class='button1' background=$default->owl_graphics_url/$default->sButtonStyle/ui_misc/button1_fill.jpg>"); 2196 print("\t\t<td class='button1'>"); 2197 print("<input class='fbuttonup1' type='submit' value='$owl_lang->btn_back' alt='$owl_lang->alt_back' title='$owl_lang->alt_back' onclick='history.back();' onmouseover=\"highlightButton('fbuttondown1')\" onmouseout=\"highlightButton('fbuttonup1')\"></input>"); 2198 print("</td>\n</tr>\n</table>\n"); 2199 print("</td>\n</tr>\n"); 2200 2201 2202 print("</table>\n"); 2203 print("</td>\n</tr>\n"); 2204 print("</table>\n"); 2205 2206 fPrintButtonSpace(12, 1); 2207 print("</td>\n</tr>\n"); 2208 print("</table>\n"); 2209 2210 //print("</table>\n"); 2211 if (file_exists("./lib/footer.inc")) 2212 { 2213 require ("./lib/footer.inc"); 2214 } 2215 else 2216 { 2217 require ("../lib/footer.inc"); 2218 } 2219 exit; 2220 } 2221 else 2222 { 2223 $lastused = time(); 2224 $sql = new Owl_DB; 2225 if (!($default->remember_me)) 2226 { 2227 $sql->query("UPDATE $default->owl_sessions_table set lastused = '$lastused' where usid = '$userid' and sessid = '$sess'"); 2228 } 2229 elseif (!(isset($HTTP_COOKIE_VARS["owl_sessid"]))) 2230 { 2231 $sql->query("UPDATE $default->owl_sessions_table set lastused = '$lastused' where usid = '$userid' and sessid = '$sess'"); 2232 } 2233 } 2234 } 2235 else 2236 { 2237 $usergroupid = "DENIED"; 2238 $user = "DENIED"; 2239 } 2240 2241 function checkrequirements() 2242 { 2243 global $default; 2244 global $owl_lang; 2245 2246 $status = 0; 2247 2248 if (version_compare(phpversion(), $default->phpversion) == -1) 2249 { 2250 print("<center><h3>$owl_lang->err_bad_version_1<br />"); 2251 print("$default->phpversion<br />"); 2252 print("$owl_lang->err_bad_version_2<br />"); 2253 print phpversion(); 2254 print("<br />$owl_lang->err_bad_version_3</h3></center>"); 2255 $status = 1; 2256 } 2257 if ($default->debug == true) 2258 { 2259 if (!file_exists($default->owl_tmpdir)) 2260 { 2261 print("<center><h3>$owl_lang->debug_tmp_not_exists</h3></center>"); 2262 $status = 1; 2263 } 2264 else 2265 { 2266 if (!is_writable($default->owl_tmpdir)) 2267 { 2268 print("<center><h3>$owl_lang->debug_tmp_not_writeable</h3></center>"); 2269 print("</h3>"); 2270 $status = 1; 2271 } 2272 } 2273 2274 if (!file_exists($default->owl_FileDir . "/" . fid_to_name(1))) 2275 { 2276 print("<center><h3>$owl_lang->debug_doc_not_exists</h3></center>"); 2277 $status = 1; 2278 } 2279 else 2280 { 2281 if (!is_writable($default->owl_FileDir . "/" . fid_to_name(1))) 2282 { 2283 print("<center><h3>$owl_lang->debug_doc_not_writeable</h3></center>"); 2284 $status = 1; 2285 } 2286 } 2287 2288 2289 if(ini_get('safe_mode') == 1) 2290 { 2291 print("<center><h3>OWL REQUIRES SAFE MODE TO BE Off</h3></center>"); 2292 $status = 1; 2293 } 2294 } 2295 2296 return $status; 2297 } 2298 2299 function myExec($_cmd, &$lines, &$errco) 2300 { 2301 $cmd = "$_cmd ; echo $?"; 2302 exec($cmd, $lines); 2303 // Get rid of the last errco line... 2304 $errco = (integer) array_pop($lines); 2305 if (count($lines) == 0) 2306 { 2307 return ""; 2308 } 2309 else 2310 { 2311 return $lines[count($lines) - 1]; 2312 } 2313 } 2314 2315 function myDelete($file) 2316 { 2317 if (file_exists($file)) 2318 { 2319 if (is_dir($file)) 2320 { 2321 $handle = opendir($file); 2322 while ($filename = readdir($handle)) 2323 { 2324 if ($filename != "." && $filename != "..") 2325 { 2326 myDelete($file . "/" . $filename); 2327 } 2328 } 2329 closedir($handle); 2330 rmdir($file); 2331 } 2332 else 2333 { 2334 unlink($file); 2335 } 2336 } 2337 } 2338 2339 function printError($message, $submessage = "", $type = "ERROR") 2340 { 2341 global $default; 2342 global $sess, $parent, $expand, $order, $sortorder , $sortname, $userid; 2343 global $language; 2344 global $owl_lang; 2345 2346 if (file_exists("./lib/header.inc")) 2347 { 2348 include_once ("./lib/header.inc"); 2349 include_once ("./lib/userheader.inc"); 2350 } 2351 else 2352 { 2353 if (file_exists("../lib/header.inc")) 2354 { 2355 include_once ("../lib/header.inc"); 2356 include_once ("../lib/userheader.inc"); 2357 } 2358 else 2359 { 2360 include_once("$default->owl_fs_root/lib/header.inc"); 2361 include_once("$default->owl_fs_root/lib/userheader.inc"); 2362 } 2363 } 2364 if (isset($parent)) 2365 { 2366 if (check_auth($parent, "folder_view", $userid) != "1") 2367 { 2368 $sql = new Owl_DB; 2369 $sql->query("SELECT * from $default->owl_folders_table where id = '$parent'"); 2370 $sql->next_record(); 2371 $parent = $sql->f("parent"); 2372 } 2373 } 2374 2375 print("<center>"); 2376 if ($expand == 1) 2377 { 2378 print("<table class='border1' cellspacing='0' cellpadding='0' border='0' width='$default->table_expand_width'><tr><td align='left' valign='top' width='100%'>\n"); 2379 } 2380 else 2381 { 2382 print("<table class='border1' cellspacing='0' cellpadding='0' border='0' width='$default->table_collapse_width'><tr><td align='left' valign='top' width='100%'>\n"); 2383 } 2384 fPrintButtonSpace(12, 1); 2385 print("<br />\n"); 2386 2387 print("<table class='border2' cellspacing='0' cellpadding='0' border='0' width='100%'><tr><td align='left' valign='top' width='100%'>\n"); 2388 2389 if ($default->show_prefs == 1 or $default->show_prefs == 3) 2390 { 2391 fPrintPrefs(); 2392 } 2393 fPrintButtonSpace(12, 1); 2394 print("<br />\n"); 2395 2396 print("<table class='margin2' cellspacing='0' cellpadding='0' border='0' width='100%'>\n"); 2397 print("<tr>\n"); 2398 print("<td align='left' valign='top'>\n"); 2399 print("<table cellspacing='0' cellpadding='0' border='0' width='100%'>\n"); 2400 //print("<tr>\n"); 2401 2402 fPrintFormTextLine("--- $type ---", "", "", $message , "", true); 2403 2404 if(!empty($submessage)) 2405 { 2406 fPrintFormTextLine("--- DETAILS ---", "", "", $submessage , "", true); 2407 } 2408 2409 print("<tr>"); 2410 print("<td class='form1'>"); 2411 fPrintButtonSpace(1, 1); 2412 print("</td>"); 2413 print("<td class='form2'>"); 2414 print("<input class='fbuttonup1' type='submit' value='$owl_lang->btn_back' alt='$owl_lang->alt_back' title='$owl_lang->alt_back' onclick='history.back();' onmouseover=\"highlightButton('fbuttondown1')\" onmouseout=\"highlightButton('fbuttonup1')\"></input>"); 2415 print("</td>"); 2416 print("</tr>"); 2417 2418 print("</table>\n"); 2419 print("</td></tr></table>\n"); 2420 fPrintButtonSpace(12, 1); 2421 2422 print("</td></tr></table>\n"); 2423 if (file_exists("./lib/footer.inc")) 2424 { 2425 include ("./lib/footer.inc"); 2426 } 2427 else 2428 { 2429 if (file_exists("../lib/footer.inc")) 2430 { 2431 include ("../lib/footer.inc"); 2432 } 2433 else 2434 { 2435 include("$default->owl_fs_root/lib/footer.inc"); 2436 } 2437 } 2438 exit(); 2439 } 2440 2441 function getuserprefs () 2442 { 2443 global $default, $userid; 2444 2445 if ($userid == "" ) 2446 { 2447 $iUid = $default->anon_user; 2448 } 2449 else 2450 { 2451 $iUid = $userid; 2452 } 2453 2454 2455 $sql = new Owl_DB; 2456 $sql->query("SELECT firstdir, homedir, buttonstyle from $default->owl_users_table where id = '$iUid'"); 2457 $sql->next_record(); 2458 $default->HomeDir = $sql->f("homedir"); 2459 $default->FirstDir = $sql->f("firstdir"); 2460 $default->sButtonStyle = $sql->f("buttonstyle"); 2461 } 2462 2463 function getprefs () 2464 { 2465 global $default, $userid; 2466 2467 define ("LOGIN", "1"); 2468 define ("LOGIN_FAILED", "2"); 2469 define ("LOGOUT", "3"); 2470 define ("FILE_DELETED", "4"); 2471 define ("FILE_UPLOAD", "5"); 2472 define ("FILE_UPDATED", "6"); 2473 define ("FILE_DOWNLOADED", "7"); 2474 define ("FILE_CHANGED", "8"); 2475 define ("FILE_LOCKED", "9"); 2476 define ("FILE_UNLOCKED", "10"); 2477 define ("FILE_EMAILED", "11"); 2478 define ("FILE_MOVED", "12"); 2479 define ("FOLDER_CREATED", "13"); 2480 define ("FOLDER_DELETED", "14"); 2481 define ("FOLDER_MODIFIED", "15"); 2482 define ("FOLDER_MOVED", "16"); 2483 define ("FORGOT_PASS", "17"); 2484 define ("USER_REG", "18"); 2485 define ("FILE_VIEWED", "19"); 2486 define ("FILE_VIRUS", "20"); 2487 define ("FILE_COPIED", "21"); 2488 define ("FOLDER_COPIED", "22"); 2489 define ("FILE_LINKED", "23"); 2490 2491 $sql = new Owl_DB; 2492 $sql->query("SELECT * from $default->owl_prefs_table"); 2493 $sql->next_record(); 2494 2495 $default->owl_email_from = $sql->f("email_from"); 2496 $default->owl_email_fromname = $sql->f("email_fromname"); 2497 $default->owl_email_replyto = $sql->f("email_replyto"); 2498 $default->owl_email_server = $sql->f("email_server"); 2499 $default->owl_email_subject = $sql->f("email_subject"); 2500 $default->use_smtp = $sql->f("use_smtp"); 2501 $default->use_smtp_auth = $sql->f("use_smtp_auth"); 2502 $default->smtp_auth_login = $sql->f("smtp_auth_login"); 2503 $default->smtp_passwd = $sql->f("smtp_passwd"); 2504 // 2505 // LookAtHD is not supported with $default->owl_use_fs = false 2506 // 2507 if ($default->owl_use_fs) 2508 { 2509 $default->owl_LookAtHD = $sql->f("lookathd"); 2510 } 2511 else 2512 { 2513 if (substr(php_uname(), 0, 7) == "Windows") 2514 { 2515 $default->owl_compressed_database = 0; 2516 } 2517 $default->owl_LookAtHD = "false"; 2518 } 2519 2520 $default->owl_lookAtHD_del = $sql->f("lookathddel"); 2521 $default->owl_def_file_security = $sql->f("def_file_security"); 2522 $default->owl_def_file_group_owner = $sql->f("def_file_group_owner"); 2523 $default->owl_def_file_owner = $sql->f("def_file_owner"); 2524 $default->owl_def_file_title = $sql->f("def_file_title"); 2525 $default->owl_def_file_meta = $sql->f("def_file_meta"); 2526 $default->owl_def_fold_security = $sql->f("def_fold_security"); 2527 $default->owl_def_fold_group_owner = $sql->f("def_fold_group_owner"); 2528 $default->owl_def_fold_owner = $sql->f("def_fold_owner"); 2529 $default->max_filesize = $sql->f("max_filesize"); 2530 $default->owl_timeout = $sql->f("timeout"); 2531 if ($sql->f("tmpdir") == "") 2532 { 2533 $default->owl_tmpdir = $default->owl_FileDir; 2534 $default->owl_tmpdir .= "/" . fid_to_name(1); 2535 } 2536 else 2537 { 2538 $default->owl_tmpdir = $sql->f("tmpdir"); 2539 } 2540 $default->expand = $sql->f("expand"); 2541 $default->owl_version_control = $sql->f("version_control"); 2542 $default->major_revision = $sql->f("major_revision"); 2543 $default->minor_revision = $sql->f("minor_revision"); 2544 2545 $default->restrict_view = $sql->f("restrict_view"); 2546 $default->dbdump_path = $sql->f("dbdump_path"); 2547 $default->gzip_path = $sql->f("gzip_path"); 2548 $default->tar_path = $sql->f("tar_path"); 2549 $default->unzip_path = $sql->f("unzip_path"); 2550 $default->pod2html_path = $sql->f("pod2html_path"); 2551 $default->pdftotext_path = $sql->f("pdftotext_path"); 2552 $default->wordtotext_path = $sql->f("wordtotext_path"); 2553 $default->file_perm = $sql->f("file_perm"); 2554 $default->folder_perm = $sql->f("folder_perm"); 2555 2556 $default->anon_ro = $sql->f("anon_ro"); 2557 $default->anon_user = $sql->f("anon_user"); 2558 $default->file_admin_group = $sql->f("file_admin_group"); 2559 2560 $default->hide_backup = $sql->f("hide_backup"); 2561 2562 $default->collect_trash = $sql->f("collect_trash"); 2563 if ($sql->f("trash_can_location") == "") 2564 { 2565 $default->trash_can_location = $default->owl_FileDir . "/TrashCan"; 2566 } 2567 else 2568 { 2569 $default->trash_can_location = $sql->f("trash_can_location"); 2570 } 2571 2572 $default->allow_popup = $sql->f("allow_popup"); 2573 $default->show_file_stats = $sql->f("status_bar_location"); 2574 2575 $default->show_prefs = $sql->f("pref_bar"); 2576 $default->show_search = $sql->f("search_bar"); 2577 $default->show_bulk = $sql->f("bulk_buttons"); 2578 $default->show_action = $sql->f("action_buttons"); 2579 $default->show_folder_tools = $sql->f("folder_tools"); 2580 2581 //$default->hide_bulk = $sql->f("hide_bulk"); 2582 // 2583 // Logging options 2584 // 2585 $default->logging = $sql->f("logging"); 2586 $default->log_file = $sql->f("log_file"); 2587 $default->log_login = $sql->f("log_login"); 2588 $default->log_rec_per_page = $sql->f("log_rec_per_page"); 2589 // 2590 // Sticky loggin (remember me Link) 2591 // 2592 $default->remember_me = $sql->f("remember_me"); 2593 $default->cookie_timeout = $sql->f("cookie_timeout"); 2594 2595 // 2596 // Self Register options 2597 // 2598 $default->self_reg = $sql->f("self_reg"); 2599 $default->self_reg_quota = $sql->f("self_reg_quota"); 2600 $default->self_reg_notify = $sql->f("self_reg_notify"); 2601 $default->self_reg_attachfile = $sql->f("self_reg_attachfile"); 2602 $default->self_reg_disabled = $sql->f("self_reg_disabled"); 2603 $default->self_reg_noprefacces = $sql->f("self_reg_noprefacces"); 2604 $default->self_reg_maxsessions = $sql->f("self_reg_maxsessions"); 2605 $default->self_reg_group = $sql->f("self_reg_group"); 2606 $default->forgot_pass = $sql->f("forgot_pass"); 2607 $default->records_per_page = $sql->f("rec_per_page"); 2608 $default->self_reg_homedir = $sql->f("self_reg_homedir"); 2609 $default->self_reg_firstdir = $sql->f("self_reg_firstdir"); 2610 2611 2612 $default->expand_disp_status = $sql->f("expand_disp_status"); 2613 $default->expand_disp_doc_num = $sql->f("expand_disp_doc_num"); 2614 $default->expand_disp_doc_type = $sql->f("expand_disp_doc_type"); 2615 $default->expand_disp_title = $sql->f("expand_disp_title"); 2616 $default->expand_disp_version = $sql->f("expand_disp_version"); 2617 $default->expand_disp_file = $sql->f("expand_disp_file"); 2618 $default->expand_disp_size = $sql->f("expand_disp_size"); 2619 $default->expand_disp_posted = $sql->f("expand_disp_posted"); 2620 $default->expand_disp_modified = $sql->f("expand_disp_modified"); 2621 $default->expand_disp_action = $sql->f("expand_disp_action"); 2622 $default->expand_disp_held = $sql->f("expand_disp_held"); 2623 2624 $default->collapse_disp_status = $sql->f("collapse_disp_status"); 2625 $default->collapse_disp_doc_num = $sql->f("collapse_disp_doc_num"); 2626 $default->collapse_disp_doc_type = $sql->f("collapse_disp_doc_type"); 2627 $default->collapse_disp_title = $sql->f("collapse_disp_title"); 2628 $default->collapse_disp_version = $sql->f("collapse_disp_version"); 2629 $default->collapse_disp_file = $sql->f("collapse_disp_file"); 2630 $default->collapse_disp_size = $sql->f("collapse_disp_size"); 2631 $default->collapse_disp_posted = $sql->f("collapse_disp_posted"); 2632 $default->collapse_disp_modified = $sql->f("collapse_disp_modified"); 2633 $default->collapse_disp_action = $sql->f("collapse_disp_action"); 2634 $default->collapse_disp_held = $sql->f("collapse_disp_held"); 2635 2636 $default->expand_search_disp_score = $sql->f("expand_search_disp_score"); 2637 $default->expand_search_disp_folder_path = $sql->f("expand_search_disp_folder_path"); 2638 $default->expand_search_disp_doc_type = $sql->f("expand_search_disp_doc_type"); 2639 $default->expand_search_disp_file = $sql->f("expand_search_disp_file"); 2640 $default->expand_search_disp_size = $sql->f("expand_search_disp_size"); 2641 $default->expand_search_disp_posted = $sql->f("expand_search_disp_posted"); 2642 $default->expand_search_disp_modified = $sql->f("expand_search_disp_modified"); 2643 $default->expand_search_disp_action = $sql->f("expand_search_disp_action"); 2644 2645 $default->collapse_search_disp_score = $sql->f("collapse_search_disp_score"); 2646 $default->collapse_search_disp_folder_path = $sql->f("collapse_search_disp_folder_path"); 2647 $default->collapse_search_disp_doc_type = $sql->f("collapse_search_disp_doc_type"); 2648 $default->collapse_search_disp_file = $sql->f("collapse_search_disp_file"); 2649 $default->collapse_search_disp_size = $sql->f("collapse_search_disp_size"); 2650 $default->collapse_search_disp_posted = $sql->f("collapse_search_disp_posted"); 2651 $default->collapse_search_disp_modified = $sql->f("collapse_search_disp_modified"); 2652 $default->collapse_search_disp_action = $sql->f("collapse_search_disp_action"); 2653 2654 $default->hide_folder_doc_count = $sql->f("hide_folder_doc_count"); 2655 $default->old_action_icons = $sql->f("old_action_icons"); 2656 $default->search_result_folders = $sql->f("search_result_folders"); 2657 $default->restore_file_prefix = $sql->f("restore_file_prefix"); 2658 2659 2660 $default->doc_id_prefix = $sql->f("doc_id_prefix"); 2661 $default->doc_id_num_digits = $sql->f("doc_id_num_digits"); 2662 2663 $default->view_doc_in_new_window = $sql->f("view_doc_in_new_window"); 2664 2665 $default->admin_login_to_browse_page = $sql->f("admin_login_to_browse_page"); 2666 2667 $default->save_keywords_to_db = $sql->f("save_keywords_to_db"); 2668 $default->anon_access = $sql->f("anon_ro"); 2669 2670 $default->document_peer_review = $sql->f("peer_review"); 2671 $default->document_peer_review_optional = $sql->f("peer_opt"); 2672 $default->hide_folder_size = $sql->f("folder_size"); 2673 $default->use_zip_for_folder_download = $sql->f("download_folder_zip"); 2674 $default->display_password_override = $sql->f("display_password_override"); 2675 $default->virus_path = $sql->f("virus_path"); 2676 2677 if (!$default->old_action_icons) 2678 { 2679 require_once ($default->owl_fs_root . "/scripts/phplayersmenu/lib/PHPLIB.php"); 2680 require_once ($default->owl_fs_root . "/scripts/phplayersmenu/lib/layersmenu-common.inc.php"); 2681 require_once ($default->owl_fs_root . "/scripts/phplayersmenu/lib/layersmenu.inc.php"); 2682 } 2683 } 2684 2685 function fIsQuotaEnabled($current_user) 2686 { 2687 global $default ; 2688 global $owl_lang; 2689 2690 $quota_max = 0; 2691 $sql = new Owl_DB; 2692 $sql->query("SELECT * from $default->owl_users_table where id = '$current_user'"); 2693 while ($sql->next_record()) 2694 { 2695 $quota_max = $sql->f("quota_max"); 2696 } 2697 if ( $quota_max == 0) 2698 { 2699 return false; 2700 } 2701 else 2702 { 2703 return true; 2704 } 2705 } 2706 function fCalculateQuota($size, $current_user, $type) 2707 { 2708 global $default; 2709 global $owl_lang; 2710 2711 $sql = new Owl_DB; 2712 $sql->query("SELECT * from $default->owl_users_table where id = '$current_user'"); 2713 while ($sql->next_record()) 2714 { 2715 $quota_max = $sql->f("quota_max"); 2716 $quota_current = $sql->f("quota_current"); 2717 if ($type == "ADD") 2718 { 2719 $new_quota = $quota_current + $size; 2720 } 2721 elseif ($type == "DEL") 2722 { 2723 $new_quota = $quota_current - $size; 2724 } 2725 } 2726 if (($new_quota > $quota_max) and fIsQuotaEnabled($current_user)) 2727 { 2728 printError("<b class=hilite>" . uid_to_name($current_user) ."</b>: $owl_lang->err_quota" . gen_filesize($size) . "$owl_lang->err_quota_needed" . gen_filesize($quota_max - $quota_current) . "$owl_lang->err_quota_avail"); 2729 if (($quota_max - $quota_current) <= 0) 2730 { 2731 printError("$owl_lang->err_quota_exceed"); 2732 } 2733 } 2734 return $new_quota; 2735 } 2736 2737 function printfileperm($currentval, $namevariable, $printmessage, $type) 2738 { 2739 global $default; 2740 global $owl_lang; 2741 2742 $file_perm[0][0] = 0; 2743 $file_perm[1][0] = 1; 2744 $file_perm[2][0] = 2; 2745 $file_perm[3][0] = 3; 2746 $file_perm[4][0] = 4; 2747 $file_perm[5][0] = 5; 2748 $file_perm[6][0] = 6; 2749 $file_perm[7][0] = 7; 2750 $file_perm[8][0] = 8; 2751 2752 if ($type == "admin") 2753 { 2754 $file_perm[0][1] = "$owl_lang->everyoneread_ad"; 2755 $file_perm[1][1] = "$owl_lang->everyonewrite_ad"; 2756 $file_perm[2][1] = "$owl_lang->groupread_ad"; 2757 $file_perm[3][1] = "$owl_lang->groupwrite_ad"; 2758 $file_perm[4][1] = "$owl_lang->onlyyou_ad"; 2759 $file_perm[5][1] = "$owl_lang->groupwrite_ad_nod"; 2760 $file_perm[6][1] = "$owl_lang->everyonewrite_ad_nod"; 2761 $file_perm[7][1] = "$owl_lang->groupwrite_worldread_ad"; 2762 $file_perm[8][1] = "$owl_lang->groupwrite_worldread_ad_nod"; 2763 } 2764 else 2765 { 2766 $file_perm[0][1] = "$owl_lang->everyoneread"; 2767 $file_perm[1][1] = "$owl_lang->everyonewrite"; 2768 $file_perm[2][1] = "$owl_lang->groupread"; 2769 $file_perm[3][1] = "$owl_lang->groupwrite"; 2770 $file_perm[4][1] = "$owl_lang->onlyyou"; 2771 $file_perm[5][1] = "$owl_lang->groupwrite_nod"; 2772 $file_perm[6][1] = "$owl_lang->everyonewrite_nod"; 2773 $file_perm[7][1] = "$owl_lang->groupwrite_worldread"; 2774 $file_perm[8][1] = "$owl_lang->groupwrite_worldread_nod"; 2775 } 2776 2777 print("<tr>\n"); 2778 print("<td class='form1'>$printmessage</td>\n"); 2779 print("<td class='form1' width='100%'>"); 2780 print("<select class='fpull1' name='$namevariable' size='1'>\n"); 2781 foreach($file_perm as $fp) 2782 { 2783 print("<option value='$fp[0]'"); 2784 if ($fp[0] == $currentval) 2785 { 2786 print(" selected='selected'"); 2787 } 2788 print(">$fp[1]</option>\n"); 2789 } 2790 print("</select>\n</td>\n</tr>\n"); 2791 } ; 2792 2793 function owl_syslog($action, $userid, $filename, $logparent, $detail, $type) 2794 { 2795 global $default; 2796 2797 if ($default->logging == 1) 2798 { 2799 $sql = new Owl_DB; 2800 $log = 0; 2801 2802 $logdate = date("Y-m-d G:i:s"); 2803 if ($_SERVER["HTTP_CLIENT_IP"]) 2804 { 2805 $ip = $_SERVER["HTTP_CLIENT_IP"]; 2806 } elseif ($_SERVER["HTTP_X_FORWARDED_FOR"]) 2807 { 2808 $forwardedip = $_SERVER["HTTP_X_FORWARDED_FOR"]; 2809 list($ip, $ip2, $ip3, $ip4) = split (",", $forwardedip); 2810 } 2811 else 2812 { 2813 $ip = $_SERVER["REMOTE_ADDR"]; 2814 } 2815 $agent = $_SERVER["HTTP_USER_AGENT"]; 2816 if ($default->log_file == 1 && $type == "FILE") 2817 { 2818 $log = 1; 2819 } 2820 if ($default->log_login == 1 && $type == "LOGIN") 2821 { 2822 $log = 1; 2823 } 2824 if ($log == 1) 2825 { 2826 if (empty($logparent)) 2827 { 2828 $logparent = 0; 2829 } 2830 $sql->query("INSERT into $default->owl_log_table (userid, filename, action, parent, details, logdate, ip, agent, type) values ('$userid', '$filename', '$action', '$logparent', '$detail', '$logdate', '$ip', '$agent', '$type')"); 2831 } 2832 } 2833 } 2834 2835 2836 function change_ownership_perms($file, $id, $func_parent, $fileowner, $groupid, $policy, $prop_file_sec) 2837 { 2838 global $default; 2839 2840 if ( $id == "1") 2841 { 2842 $file = ""; 2843 } 2844 if (is_dir($default->owl_FileDir . "/" . find_path($func_parent) . "/" . $file)) 2845 { 2846 $sql = new Owl_DB; 2847 $smodified = $sql->now(); 2848 $sql->query("UPDATE $default->owl_folders_table SET creatorid='$fileowner', groupid='$groupid', security='$policy', smodified=$smodified WHERE id='$id'"); 2849 if ($prop_file_sec >= 0 ) 2850 { 2851 $sql = new Owl_DB; 2852 $sql->query("UPDATE $default->owl_files_table SET creatorid='$fileowner', groupid='$groupid', security='$prop_file_sec', smodified=$smodified where parent='$id'"); 2853 } 2854 2855 $sql = new Owl_DB; 2856 $sql->query("SELECT name, id from $default->owl_folders_table where parent='$id'"); 2857 while($sql->next_record()) 2858 { 2859 $newfile = $sql->f("name"); 2860 $newid = $sql->f("id"); 2861 change_ownership_perms($newfile, $newid, $id, $fileowner, $groupid, $policy, $prop_file_sec); 2862 } 2863 } 2864 else 2865 { 2866 if ($default->debug == true) 2867 { 2868 printError("DEBUG: Security Propagation attempt on a file"); 2869 } 2870 } 2871 } 2872 2873 2874 function printgroupperm($currentval, $namevariable, $printmessage, $type) 2875 { 2876 global $default; 2877 global $owl_lang; 2878 2879 $group_perm[0][0] = 50; 2880 $group_perm[1][0] = 51; 2881 $group_perm[2][0] = 52; 2882 $group_perm[3][0] = 53; 2883 $group_perm[4][0] = 54; 2884 $group_perm[5][0] = 55; 2885 $group_perm[6][0] = 56; 2886 $group_perm[7][0] = 57; 2887 $group_perm[8][0] = 58; 2888 2889 if ($type == "admin") 2890 { 2891 $group_perm[0][1] = "$owl_lang->geveryoneread_ad"; 2892 $group_perm[1][1] = "$owl_lang->geveryonewrite_ad"; 2893 $group_perm[2][1] = "$owl_lang->ggroupread_ad"; 2894 $group_perm[3][1] = "$owl_lang->ggroupwrite_ad"; 2895 $group_perm[4][1] = "$owl_lang->gonlyyou_ad"; 2896 $group_perm[5][1] = "$owl_lang->ggroupwrite_ad_nod"; 2897 $group_perm[6][1] = "$owl_lang->geveryonewrite_ad_nod"; 2898 $group_perm[7][1] = "$owl_lang->ggroupwrite_worldread_ad"; 2899 $group_perm[8][1] = "$owl_lang->ggroupwrite_worldread_ad_nod"; 2900 } 2901 else 2902 { 2903 $group_perm[0][1] = "$owl_lang->geveryoneread"; 2904 $group_perm[1][1] = "$owl_lang->geveryonewrite"; 2905 $group_perm[2][1] = "$owl_lang->ggroupread"; 2906 $group_perm[3][1] = "$owl_lang->ggroupwrite"; 2907 $group_perm[4][1] = "$owl_lang->gonlyyou"; 2908 $group_perm[5][1] = "$owl_lang->ggroupwrite_nod"; 2909 $group_perm[6][1] = "$owl_lang->geveryonewrite_nod"; 2910 $group_perm[7][1] = "$owl_lang->ggroupwrite_worldread"; 2911 $group_perm[8][1] = "$owl_lang->ggroupwrite_worldread_nod"; 2912 } 2913 2914 print("<tr>\n"); 2915 print("<td class='form1'>$printmessage</td>\n"); 2916 print("<td class='form1' width='100%'>"); 2917 print("<select class='fpull1' name='$namevariable' size='1'>\n"); 2918 foreach($group_perm as $fp) 2919 { 2920 print("<option value='$fp[0]' "); 2921 if ($fp[0] == $currentval) 2922 { 2923 print("selected='selected'"); 2924 } 2925 print(">$fp[1]</option>\n"); 2926 } 2927 print("</select></td>\n</tr>\n"); 2928 } ; 2929 2930 function get_title_tag($chaine) 2931 { 2932 $fp = fopen ($chaine, 'r'); 2933 while (! feof ($fp)) 2934 { 2935 $contenu .= fgets ($fp, 1024); 2936 if (stristr($contenu, '</title>')) 2937 { 2938 break; 2939 } 2940 } 2941 if (eregi("<title>(.*)</title>", $contenu, $out)) 2942 { 2943 return $out[1]; 2944 } 2945 else 2946 { 2947 return false; 2948 } 2949 } 2950 2951 function RndInt($Format) 2952 { 2953 switch ($Format) 2954 { 2955 case "letter": 2956 $Rnd = rand(0, 25); 2957 if ($Rnd > 25) 2958 { 2959 $Rnd = $Rnd - 1; 2960 } 2961 break; 2962 case "number": 2963 $Rnd = rand(0, 9); 2964 if ($Rnd > 9) 2965 { 2966 $Rnd = $Rnd - 1; 2967 } 2968 break; 2969 } 2970 return $Rnd; 2971 } 2972 2973 function GenRandPassword() 2974 { 2975 /** 2976 * RANDOM PASSWORD GENERATION ALGORITHM 2977 * PROGRAMMED BY: BRIAN GRIFFIN 2978 * January 1, 2003 2979 * MXrider005@hotmail.com 2980 * 2981 * You can use this freely. Just don't credit it as your own work! And please e-mail me if you do just to let me know. Thanks. 2982 */ 2983 // DEFINE STRINGS TO USE FOR CHARACTER C // OMBINATIONS IN THE PASSWORD 2984 $LCase = "abcdefghijklmnopqrstuvwxyz"; 2985 $UCase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 2986 $Integer = "0123456789"; 2987 // DEFINE CONSTANTS FOR ALGORTTHM 2988 define("LEN", "1"); 2989 /** 2990 * THIS FUNCTION GENERATES A RANDOM NUMBER THAT WILL BE USED TO 2991 * RANDOMLY SELECT CHARACTERS FROM THE STRINGS ABOVE 2992 */ 2993 2994 /** 2995 * RUN THE FUNCTION TO GENERATE RANDOM INTEGERS FOR EACH OF THE 2996 * 6 CHARACTERS IN THE PASSWORD PRODUCED. 2997 */ 2998 $a = RndInt("letter"); 2999 $b = RndInt("letter"); 3000 $c = RndInt("letter"); 3001 $d = RndInt("letter"); 3002 $e = RndInt("number"); 3003 $f = RndInt("number"); 3004 // EXTRACT 6 CHARACTERS RANDOMLY FROM TH // E DEFINITION STRINGS 3005 $L1 = substr($LCase, $a, LEN); 3006 $L2 = substr($LCase, $b, LEN); 3007 $U1 = substr($UCase, $c, LEN); 3008 $U2 = substr($UCase, $d, LEN); 3009 $I1 = substr($Integer, $e, LEN); 3010 $I2 = substr($Integer, $f, LEN); 3011 // COMBINE THE CHARACTERS AND DISPLAY TH // E NEW PASSWORD 3012 $PW = $L1 . $U2 . $I1 . $L2 . $I2 . $U1; 3013 return $PW; 3014 } 3015 3016 if (!$sess && !$loginname && !$login) 3017 { 3018 if (!isset($fileid)) 3019 { 3020 $sql = new Owl_DB; 3021 $sql->query("SELECT * from $default->owl_users_table where id = '$default->anon_user'"); 3022 $sql->next_record(); 3023 if ($sql->num_rows() == 1) 3024 { 3025 $accountname = $sql->f("name"); 3026 if ($sql->f("disabled") != 1) 3027 $userid = $default->anon_user; 3028 else 3029 { 3030 if ($_SERVER["PHP_SELF"] != $default->owl_root_url . "/register.php") 3031 header("Location: " . $default->owl_root_url . "/index.php?login=1"); 3032 } 3033 } 3034 else 3035 { 3036 if ($_SERVER["PHP_SELF"] != $default->owl_root_url . "/register.php") 3037 header("Location: " . $default->owl_root_url . "/index.php?login=1&failure=4"); 3038 } 3039 } 3040 else 3041 { 3042 if ($default->anon_ro > 0) 3043 { 3044 header("Location: " . $default->owl_root_url . "/index.php?login=1&fileid=$fileid&parent=$parent"); 3045 } 3046 else 3047 { 3048 $sql = new Owl_DB; 3049 $sql->query("SELECT * from $default->owl_users_table where id = '$default->anon_user'"); 3050 $sql->next_record(); 3051 if ($sql->num_rows() == 1) 3052 { 3053 $accountname = $sql->f("name"); 3054 if ($sql->f("disabled") != 1) 3055 { 3056 $userid = $default->anon_user; 3057 } 3058 else 3059 { 3060 if ($_SERVER["PHP_SELF"] != $default->owl_root_url . "/register.php") 3061 { 3062 header("Location: " . $default->owl_root_url . "/index.php?login=1"); 3063 } 3064 } 3065 } 3066 else 3067 { 3068 if ($_SERVER["PHP_SELF"] != $default->owl_root_url . "/register.php") 3069 { 3070 header("Location: " . $default->owl_root_url . "/index.php?login=1&failure=4"); 3071 } 3072 } 3073 } 3074 3075 3076 //header("Location: " . $default->owl_root_url . "/index.php?login=1&fileid=$fileid&parent=$parent"); 3077 } 3078 } 3079 3080 if (!$sess && $loginname) 3081 { 3082 $sql = new Owl_DB; 3083 $sql->query("SELECT * from $default->owl_users_table where id = '$default->anon_user'"); 3084 $sql->next_record(); 3085 if ($sql->num_rows() == 1) 3086 { 3087 if ($sql->f("disabled") != 1) 3088 { 3089 $userid = $default->anon_user; 3090 } 3091 else 3092 { 3093 //header("Location: " . $default->owl_root_url . "/index.php?login=1¤tdb=$default->owl_current_db"); 3094 header("Location: " . $default->owl_root_url . "/index.php?login=1"); 3095 } 3096 } 3097 else 3098 { 3099 header("Location: " . $default->owl_root_url . "/index.php?login=1"); 3100 } 3101 } 3102 3103 if (!$sess && $login) 3104 { 3105 if ($_SERVER["PHP_SELF"] != $default->owl_root_url . "/index.php") 3106 header("Location: " . $default->owl_root_url . "/index.php?login=1"); 3107 } 3108 // 3109 // PDF and Text File Search Index Functions BEGIN 3110 // 3111 // DoesFileIDContainKeyword: Pass a file id from the files table and a keyword. 3112 // pretty quickly tells you if that keyword is in that file, actually very quickly. 3113 3114 function DoesFileIDContainKeyword($fileid, $keyword) 3115 { 3116 global $default; 3117 $sql = new Owl_DB; 3118 $sql->query("SELECT * from $default->owl_wordidx where word='$keyword'"); 3119 $sql->query("SELECT * from $default->owl_wordidx where word like '%$keyword%'"); 3120 if ($sql->num_rows() > 0) 3121 { 3122 $glue = ""; 3123 while($sql->next_record()) 3124 { 3125 $query .= $glue . " wordid = '" . $sql->f("wordid") . "'"; 3126 $glue = " OR "; 3127 } 3128 } 3129 else 3130 { 3131 $query = "wordid = '-1'"; 3132 } 3133 3134 $sql->query("SELECT * from $default->owl_searchidx where ($query) and owlfileid = '$fileid'"); 3135 3136 return $sql->num_rows(); 3137 } 3138 3139 function IndexATextFile($filename, $owlfileid) 3140 { 3141 global $default; 3142 3143 $fileidnum = $owlfileid; 3144 3145 $sql = new Owl_DB; 3146 $sql->query("SELECT * from $default->owl_wordidx"); //Import all words and indexes 3147 $nextwordindex = 0; 3148 $wordindex = array(); 3149 while ($sql->next_record()) // this may get ugly, we could have 100K words and indexes, they gotta go into memory. 3150 { 3151 $wordindex[$sql->f("word")] = $sql->f("wordid"); 3152 if ($sql->f("wordid") > $nextwordindex) 3153 { 3154 $nextwordindex = $sql->f("wordid"); //get largest word index in table 3155 } 3156 } 3157 $nextwordindex++; 3158 3159 // Note: again, here we've just read in the big wordidx, we should index as many 3160 // files as possible while we have this index in memory, here we 3161 // only index a single filename, but if someone wants to greatly improve performance, 3162 // index an array of filenames here... 3163 if (file_exists($filename)) 3164 { 3165 $fp = fopen($filename, "rb"); 3166 while (!feof($fp)) 3167 { 3168 $line = fgets($fp, 128); 3169 $line = strtolower($line); 3170 //$wordtemp = preg_split("/\W/", $line); //split line into words a word is any # of A-Za-z's separated by somethign not a-zA-Z 3171 $wordtemp = preg_split("/\s+/", $line); //split line into words a word is any # of A-Za-z's separated by somethign not a-zA-Z 3172 if (!isset($wordtemp)) continue; 3173 3174 foreach($wordtemp as $wd) 3175 { 3176 $wd = stripslashes(ereg_replace("[$default->list_of_chars_to_remove_from_wordidx]","",str_replace("]", "", str_replace("[", "",$wd)))); 3177 3178 if (strlen(trim($wd)) > 0 and strlen(trim($wd)) < 128) 3179 { 3180 $words[$wd]++; //keep a count of how often each word is seen 3181 //print("WORDS: $words[$wd] ---- "); 3182 if ($words[$wd] == 1) // if this is the first time we've seen this word in this document... 3183 { 3184 if ($wordindex[$wd]) // if this word was already in the wordidx table... 3185 { 3186 $sql->query("INSERT into $default->owl_searchidx values('$wordindex[$wd]','$fileidnum')"); //add a searchidx table entry for this fileidnum (owlidnum) 3187 } 3188 else // if word not in word index, add to both wordidx and searchidx 3189 { 3190 if (!empty($default->words_to_exclude_from_wordidx)) 3191 { 3192 array($WordList); 3193 $WordList = $default->words_to_exclude_from_wordidx; 3194 3195 $checkword = str_replace("+", "\+", $wd); 3196 $checkword = str_replace("'", "\'", $checkword); 3197 $checkword = str_replace("{", "\{", $checkword); 3198 $checkword = str_replace("}", "\}", $checkword); 3199 3200 if (!(preg_grep("/$checkword/", $WordList))) 3201 { 3202 $wordindex[$wd] = $nextwordindex; //first remember this word as being in the wordindex 3203 $sql->query("INSERT into $default->owl_searchidx values('$wordindex[$wd]', '$fileidnum')"); //add pointer to owlidnum for this wordindexnum 3204 3205 $wd = ereg_replace("'", "\\'" , $wd); 3206 $sql->query("SELECT wordid from $default->owl_wordidx where word = '$wd'"); 3207 $numrows = $sql->num_rows($sql); 3208 if ( $numrows == 0 ) 3209 { 3210 $sql->query("INSERT into $default->owl_wordidx values('$nextwordindex', '$wd')"); 3211 $nextwordindex++; 3212 } 3213 } 3214 } 3215 else 3216 { 3217 $wordindex[$wd] = $nextwordindex; //first remember this word as being in the wordindex 3218 $sql->query("INSERT into $default->owl_searchidx values('$wordindex[$wd]', '$fileidnum')"); //add pointer to owlidnum for this wordindexnum 3219 3220 $wd = ereg_replace("'", "\\'" , $wd); 3221 $sql->query("SELECT wordid from $default->owl_wordidx where word = '$wd'"); 3222 $numrows = $sql->num_rows($sql); 3223 if ( $numrows == 0 ) 3224 { 3225 $sql->query("INSERT into $default->owl_wordidx values('$nextwordindex', '$wd')"); 3226 $nextwordindex++; 3227 } 3228 } 3229 } 3230 } //if first instance of this word... 3231 } 3232 } //for each word 3233 } //while!feof 3234 } 3235 else 3236 { 3237 if ($default->debug == true) 3238 { 3239 printError("DEBUG: $owl_lang->err_file_indexing"); 3240 } 3241 } 3242 } 3243 3244 function IndexABigString($bigstring, $owlfileid) 3245 { 3246 global $default; 3247 3248 $fileidnum = $owlfileid; 3249 3250 $sql = new Owl_DB; 3251 $sql->query("SELECT * from $default->owl_wordidx"); //Import all words and indexes 3252 $nextwordindex = 0; 3253 $wordindex = array(); 3254 while ($sql->next_record()) // this may get ugly, we could have 100K words and indexes, they gotta go into memory. 3255 { 3256 $wordindex[$sql->f("word")] = $sql->f("wordid"); 3257 if ($sql->f("wordid") > $nextwordindex) 3258 { 3259 $nextwordindex = $sql->f("wordid"); //get largest word index in table 3260 } 3261 } 3262 $nextwordindex++; 3263 3264 // Note: again, here we've just read in the big wordidx, we should index as many 3265 // files as possible while we have this index in memory, here we 3266 // only index a single filename, but if someone wants to greatly improve performance, 3267 // index an array of filenames here... 3268 $wordtemp = preg_split("/\s+/", strtolower($bigstring)); //split line into words a word is any # of A-Za-z's separated by somethign not a-zA-Z 3269 if (!isset($wordtemp)) return; 3270 3271 foreach($wordtemp as $wd) 3272 { 3273 $wd = ereg_replace("[$default->list_of_chars_to_remove_from_wordidx]","",$wd); 3274 3275 if (strlen(trim($wd)) > 0) 3276 { 3277 $words[$wd]++; //keep a count of how often each word is seen 3278 //print("WORDS: $words[$wd] ---- "); 3279 if ($words[$wd] == 1) // if this is the first time we've seen this word in this document... 3280 { 3281 if ($wordindex[$wd]) // if this word was already in the wordidx table... 3282 { 3283 $sql->query("INSERT into $default->owl_searchidx values('$wordindex[$wd]','$fileidnum')"); //add a searchidx table entry for this fileidnum (owlidnum) 3284 } 3285 else // if word not in word index, add to both wordidx and searchidx 3286 { 3287 $wordindex[$wd] = $nextwordindex; //first remember this word as being in the wordindex 3288 $sql->query("INSERT into $default->owl_searchidx values('$wordindex[$wd]', '$fileidnum')"); //add pointer to owlidnum for this wordindexnum 3289 3290 $wd = ereg_replace("'", "\\'" , $wd); 3291 $sql->query("SELECT wordid from $default->owl_wordidx where word = '$wd'"); 3292 $numrows = $sql->num_rows($sql); 3293 if ( $numrows == 0 ) 3294 { 3295 $sql->query("INSERT into $default->owl_wordidx values('$nextwordindex', '$wd')"); 3296 $nextwordindex++; 3297 } 3298 } 3299 } //if first instance of this word... 3300 } 3301 } //for each word 3302 } 3303 3304 // When a file gets delete/removed, this should be called to update the indexing 3305 // tables 3306 function fDeleteFileIndexID($fidtoremove) 3307 { 3308 global $default; 3309 $sql = new Owl_DB; 3310 3311 $sql->query("DELETE from $default->owl_searchidx where owlfileid = $fidtoremove"); 3312 // Note, I'm leaving the wordidx table alone, it can only grow so large as 3313 // there are only so many words in the language, will make indexing future items a bit faster methinks 3314 } 3315 3316 function fIndexAFile($new_name, $newpath, $id) 3317 { 3318 global $default, $sess; 3319 // IF the file was inserted in the database now INDEX it for SEARCH. 3320 $sSearchExtension = fFindFileExtension($new_name); 3321 3322 if ($sSearchExtension == 'pdf' || $sSearchExtension == 'c' || $sSearchExtension == 'html' || $sSearchExtension == 'htm' || $sSearchExtension == 'php' || $sSearchExtension == 'pl' || $sSearchExtension == 'txt' || $sSearchExtension == 'doc' || $sSearchExtension == 'xls' or $sSearchExtension == 'sxw') 3323 { 3324 if(file_exists($default->pdftotext_path) and $sSearchExtension == 'pdf') 3325 { 3326 $command = $default->pdftotext_path . ' "' . $newpath . '" "' . $default->owl_tmpdir . "/" . $new_name . '.text"'; 3327 3328 $last_line = system($command, $retval); 3329 if ($retval > 0) 3330 { 3331 if ($default->debug == true) 3332 { 3333 switch ($retval) 3334 { 3335 case "1": 3336 $sPdfError = "Error opening a PDF file. (Not A PDF File?)"; 3337 break; 3338 case "2": 3339 $sPdfError = "Error opening an ouput file. ($default->owl_tmpdir Writeable by the webserver?)"; 3340 break; 3341 } 3342 printError('DEBUG: Indexing PDF File \'' . $newpath . '\' Failed:' , $sPdfError); 3343 } 3344 } 3345 IndexATextFile($default->owl_tmpdir . "/" . $new_name . '.text', $id); 3346 unlink($default->owl_tmpdir . "/" . $new_name . '.text'); 3347 } 3348 elseif (file_exists($default->wordtotext_path) and $sSearchExtension == 'doc') 3349 { 3350 //$command = "/bin/sh -c" . ' "' . $default->wordtotext_path . ' ' . $newpath . '"' . ' > "' . $default->owl_tmpdir . "/" . $new_name . '.text"'; 3351 $command = $default->wordtotext_path . ' "' . $newpath . '" > "' . $default->owl_tmpdir . "/" . $new_name . '.text"'; 3352 //print("C: $command"); 3353 //exit; 3354 $last_line = system($command, $retval); 3355 if ($retval > 0) 3356 { 3357 if ($default->debug == true) 3358 { 3359 $sPdfError = "Return: $retval $last_line"; 3360 printError('DEBUG: Indexing MS WORD File \'' . $newpath . '\' Failed:' , $sPdfError); 3361 } 3362 } 3363 3364 IndexATextFile($default->owl_tmpdir . "/" . $new_name . '.text', $id); 3365 unlink($default->owl_tmpdir . "/" . $new_name . '.text'); 3366 } 3367 elseif($sSearchExtension == 'sxw') 3368 { 3369 $tmpDir = $default->owl_tmpdir . "/owltmp.$sess"; 3370 if (file_exists($tmpDir)) 3371 { 3372 myDelete($tmpDir); 3373 } 3374 3375 mkdir($tmpDir,$default->directory_mask); 3376 3377 $archive = new PclZip($newpath); 3378 $aListOfFiles = $archive->listContent(); 3379 while ($aFileDetails = current($aListOfFiles)) { 3380 if($aFileDetails["filename"] == "content.xml") 3381 { 3382 $iContentFileIndex = $aFileDetails["index"]; 3383 break; 3384 } 3385 next($aListOfFiles); 3386 } 3387 3388 if ($archive->extractByIndex($iContentFileIndex, $tmpDir) == 0) 3389 { 3390 printError("DEBUG: " .$archive->errorInfo(true), "N: $newpath P: $tmpDir"); 3391 } 3392 $text = file_get_contents("$tmpDir/content.xml"); 3393 $fp = fopen($tmpDir ."/content.xml.text", "w"); 3394 fwrite($fp, strip_tags($text)); 3395 fclose($fp); 3396 3397 IndexATextFile($tmpDir ."/content.xml.text", $id); 3398 myDelete($tmpDir); 3399 } 3400 elseif($sSearchExtension == 'xls') 3401 { 3402 $xlwords = ''; 3403 require_once ('xlread.inc'); 3404 $xl = new Spreadsheet_Excel_Reader(); 3405 $xl->read($newpath); 3406 for ($k = count($xl->sheets)-1; $k>=0; $k--) 3407 { 3408 for ($i = 1; $i <= $xl->sheets[$k]['numRows']; $i++) 3409 { 3410 for ($j = 1; $j <= $xl->sheets[$k]['numCols']; $j++) 3411 { 3412 $xlwords .= $xl->sheets[$k]['cells'][$i][$j] . ' '; 3413 } 3414 } 3415 } 3416 $xlwords = preg_replace('# +#si',' ',$xlwords); 3417 $xlwords = preg_replace('# $#si','',$xlwords); 3418 IndexABigString($xlwords, $id); 3419 } 3420 else 3421 { 3422 if ($sSearchExtension != 'pdf' and $sSearchExtension != 'doc' and $sSearchExtension != 'xls') 3423 { 3424 IndexATextFile($newpath, $id); 3425 } 3426 } 3427 } 3428 } 3429 // 3430 // PDF and Text File Search Index Functions END 3431 // 3432 function fFindFileExtension ($filename) 3433 { 3434 $filesearch = explode('.', $filename); 3435 $extensioncounter = 0; 3436 while ($filesearch[$extensioncounter + 1] != null) 3437 { 3438 // pre-append a "." separator in the name for each 3439 // subsequent part of the the name of the file. 3440 if ($extensioncounter != 0) 3441 { 3442 $firstpart = $firstpart . "."; 3443 } 3444 $firstpart = $firstpart . $filesearch[$extensioncounter]; 3445 $extensioncounter++; 3446 } 3447 if ($extensioncounter == 0) 3448 { 3449 $firstpart = $filename; 3450 $file_extension = ''; 3451 } 3452 else 3453 { 3454 $file_extension = $filesearch[$extensioncounter]; 3455 } 3456 return strtolower($file_extension); 3457 } 3458 3459 if (!function_exists("file_get_contents")) 3460 { 3461 function file_get_contents($filename, $use_include_path = 0) 3462 { 3463 $data = ""; // just to be safe. Dunno, if this is really needed 3464 $file = @fopen($filename, "rb", $use_include_path); 3465 if ($file) 3466 { 3467 while (!feof($file)) $data .= fread($file, 1024); 3468 fclose($file); 3469 } 3470 return $data; 3471 } 3472 } 3473 3474 3475 function my_copy($oldname, $newname) 3476 { 3477 if(is_file($oldname)) 3478 { 3479 $perms = fileperms($oldname); 3480 return copy($oldname, $newname) && chmod($newname, $perms); 3481 } 3482 else if(is_dir($oldname)) 3483 { 3484 my_dir_copy($oldname, $newname); 3485 } 3486 else 3487 { 3488 die("Cannot copy file: $oldname (it's neither a file nor a directory)"); 3489 } 3490 } 3491 3492 function my_dir_copy($oldname, $newname) 3493 { 3494 global $default; 3495 3496 if(!is_dir($newname)) 3497 { 3498 mkdir($newname, $default->directory_mask); 3499 } 3500 3501 $dir = opendir($oldname); 3502 while($file = readdir($dir)) 3503 { 3504 if($file == "." || $file == "..") 3505 { 3506 continue; 3507 } 3508 my_copy("$oldname/$file", "$newname/$file"); 3509 } 3510 closedir($dir); 3511 } 3512 function fCopyFolder ($Folderid, $destparent) 3513 { 3514 global $default; 3515 $GetFolder = new Owl_DB; 3516 $InsertFolder = new Owl_DB; 3517 $smodified = $InsertFolder->now(); 3518 $GetFolder->query("SELECT * from $default->owl_folders_table where id ='$Folderid'"); 3519 $GetFolder->next_record(); 3520 3521 if ($GetFolder->num_rows() == 1) 3522 { 3523 $InsertFolder->query("INSERT into $default->owl_folders_table (name, parent, security, groupid, creatorid, description, smodified) values ('". $GetFolder->f("name") ."', '" . $destparent ."', '" . $GetFolder->f("security") . "', '" . $GetFolder->f("groupid") . "', '" . $GetFolder->f("creatorid") . "', '" . $GetFolder->f("description") . "', $smodified)"); 3524 3525 $newParent = $InsertFolder->insert_id($default->owl_folders_table, 'id'); 3526 3527 $GetFiles = new Owl_DB; 3528 $PutFiles = new Owl_DB; 3529 $GetFileData = new Owl_DB; 3530 $PutFileData = new Owl_DB; 3531 $GetDoctype = new Owl_DB; 3532 $PutDoctype = new Owl_DB; 3533 $GetFiles->query("SELECT * from $default->owl_files_table where parent ='" . $GetFolder->f("id") . "'"); 3534 while ( $GetFiles->next_record() ) 3535 { 3536 // INSERT Files 3537 $PutFiles->query("INSERT into $default->owl_files_table (name,filename,f_size,creatorid,parent,created, description,metadata,security,groupid,smodified,checked_out, major_revision, minor_revision, url, doctype, approved) values ('" . $GetFiles->f("name") . "' , '" . $GetFiles->f("filename") . "' , '" . $GetFiles->f("f_size") . "' , '" . $GetFiles->f("creatorid") . "' , '$newParent', '" . $GetFiles->f("created") . "' , '" . $GetFiles->f("description") . "' , '" . $GetFiles->f("metadata") . "' , '" . $GetFiles->f("security") . "' , '" . $GetFiles->f("groupid") . "' , '" . $GetFiles->f("smodified") . "' , '" . $GetFiles->f("checked_out") . "' , '" .