Commit 97f17c1aa0bf8f96951ba5a57354ff15e32bcb90
1 parent
30c101b1
Added 4 functions
viewDocumentHistory sendHyperLink publishDocument publishDocumentToWeb git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@115 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
207 additions
and
0 deletions
lib/documentmanagement/documentManager.inc
| ... | ... | @@ -14,6 +14,7 @@ |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | 16 | require_once ("$default->owl_root_url/lib/owl.lib.php"); |
| 17 | +require_once("./phpmailer/class.phpmailer.php"); // for emailing | |
| 17 | 18 | |
| 18 | 19 | class DocumentManager { |
| 19 | 20 | |
| ... | ... | @@ -274,7 +275,213 @@ class DocumentManager { |
| 274 | 275 | return $sql->next_record(); |
| 275 | 276 | } |
| 276 | 277 | |
| 278 | +//------------------------------------------------------------ | |
| 279 | +/** | |
| 280 | + * Function viewDocumentHistory($DocumentID) | |
| 281 | + * | |
| 282 | + * This function gets all revision history for a particular document | |
| 283 | + * | |
| 284 | + * @param $DocumentID | |
| 285 | + * The id of the document whose history we wish to retrieve | |
| 286 | + * | |
| 287 | +*/ | |
| 288 | +//------------------------------------------------------------ | |
| 289 | +function viewDocumentHistory($DocumentID) | |
| 290 | +{ | |
| 291 | + // we need to first connect to the db | |
| 292 | + // then we run the query...getting all info for specific document id | |
| 293 | + // we then return the array???? or print out the info | |
| 294 | + | |
| 295 | + global $default; | |
| 296 | + $db = new Owl_DB(); | |
| 297 | + | |
| 298 | + $Sql = "SELECT * FROM " . $default->owl_document_transactions_table . " WHERE document_id = $DocumentID"; | |
| 299 | + | |
| 300 | + $result = $db->query($Sql); | |
| 301 | + $rows = $db->num_rows($result); | |
| 302 | + | |
| 303 | + | |
| 304 | + // return the result set.. | |
| 305 | + return $result; | |
| 306 | + | |
| 307 | +} | |
| 308 | + | |
| 309 | + | |
| 310 | +//------------------------------------------------------------ | |
| 311 | +/** | |
| 312 | + * Function sendHyperLink($FromEmail, $FromName, $ToEmail, $Subject, $EmailBody, $hyperlink) | |
| 313 | + * | |
| 314 | + * Sends an email containing a hyperlink to a specified recipient | |
| 315 | + * | |
| 316 | + * @param $FromEmail | |
| 317 | + * The sender's email address | |
| 318 | + * @param $FromName | |
| 319 | + * The sender's Name | |
| 320 | + * @param $ToEmail | |
| 321 | + * The recipients email address | |
| 322 | + * @param $Subject | |
| 323 | + * The subject heading for the email | |
| 324 | + * @param $EmailBody | |
| 325 | + * The Body of the email | |
| 326 | + * @param $hyperlink | |
| 327 | + * The hyperlink that should be sent | |
| 328 | + * | |
| 329 | + * @Todo ...take out the error handling or modify it | |
| 330 | + Also check for special characters | |
| 331 | +*/ | |
| 332 | +//------------------------------------------------------------ | |
| 333 | +function sendHyperLink($FromEmail, $FromName, $ToEmail, $Subject, $EmailBody, $hyperlink) | |
| 334 | +{ | |
| 335 | + global $default; | |
| 336 | + | |
| 337 | + // create a new phpmailer object. | |
| 338 | + $mail = new phpmailer(); | |
| 339 | + | |
| 340 | + //set up info | |
| 341 | + $mail->IsSMTP(); // telling the class to use SMTP | |
| 342 | + $mail->Host = $default->owl_mail_server; // SMTP server | |
| 343 | + | |
| 344 | + //get info from relevant fields. | |
| 345 | + $mail->From = $FromEmail; | |
| 346 | + $mail->FromName = $FromName; | |
| 347 | + $mail->AddAddress($ToEmail); | |
| 348 | + $mail->Subject = $Subj; | |
| 349 | + $mail->Body = $EmailBody . ' ' . $hyperlink; | |
| 350 | + $mail->WordWrap = 100; | |
| 351 | + $mail->IsHTML(true); | |
| 352 | + | |
| 353 | + //send the email | |
| 354 | + if(!$mail->Send()) | |
| 355 | + { | |
| 356 | + echo "Message was not sent"; | |
| 357 | + echo "Mailer Error: " . $mail->ErrorInfo; | |
| 358 | + } | |
| 359 | + else | |
| 360 | + { | |
| 361 | + echo "Message has been sent"; | |
| 362 | + } | |
| 363 | + | |
| 364 | +} | |
| 365 | + | |
| 366 | + | |
| 367 | +//------------------------------------------------------------ | |
| 368 | +/** | |
| 369 | + * Function publishDocument($DocumentID,$WebsiteID, $UnitID, $DTime) | |
| 370 | + * | |
| 371 | + * This function sets up a document for publication by | |
| 372 | + * inserting the various parameters into the web_documents table | |
| 373 | + * and then sets the status id corresponding to the 'Pending' Status | |
| 374 | + * | |
| 375 | + * @param $DocumentID | |
| 376 | + * The id of the document that we wish to publish | |
| 377 | + * @param $WebsiteID | |
| 378 | + * The id of the website | |
| 379 | + * @param $UnitID | |
| 380 | + * The id of the unit the document belongs to | |
| 381 | + * @param $DTime | |
| 382 | + * The Date and Time that the document was uploaded for publication | |
| 383 | + * approval...should be 'Now' where now is the D & T it was uploaded | |
| 384 | + */ | |
| 385 | +//------------------------------------------------------------ | |
| 386 | +function publishDocument($DocumentID,$WebsiteID, $UnitID, $DTime) | |
| 387 | +{ | |
| 388 | + // First need to get all info..ie docid, websiteid, unitid, | |
| 389 | + // then set the status to pending..awaiting final approval from | |
| 390 | + // whoever needs to publish it. | |
| 391 | + // then store it in the web_documents | |
| 392 | + | |
| 393 | + global $default; | |
| 394 | + $db = new Owl_DB(); | |
| 395 | + | |
| 396 | + $Sql = "SELECT * FROM " . $default->owl_web_documents_table . " WHERE document_id = $DocumentID"; | |
| 397 | + | |
| 398 | + $result = $db->query($Sql); | |
| 399 | + $row = $db->num_rows($result); | |
| 400 | + | |
| 401 | + //get the id when status set to pending | |
| 402 | + $Sql2 = "SELECT id FROM " . $default->owl_web_documents_status_table . " WHERE name = 'Pending' "; | |
| 403 | + $pending = $db->query($Sql2); | |
| 404 | + $db->next_record(); | |
| 405 | + $PendingID = $db->f("id"); | |
| 277 | 406 | |
| 407 | + // make sure document does'nt exist in the db already | |
| 408 | + if($row == 1) | |
| 409 | + { | |
| 410 | + printf("Document already awaiting approval"); | |
| 411 | + return false; | |
| 412 | + } | |
| 413 | + Else | |
| 414 | + { // insert new entry | |
| 415 | + $Sql = "INSERT INTO " . $default->owl_web_documents_table . " (document_id,web_site_id,unit_id,status_id, datetime) VALUES ($DocumentID,$WebsiteID,$UnitID, $PendingID, '$DTime')"; | |
| 416 | + $result = $db->query($Sql) ; | |
| 417 | + return true; | |
| 418 | + | |
| 419 | + } | |
| 420 | + | |
| 421 | +} | |
| 422 | + | |
| 423 | +//------------------------------------------------------------ | |
| 424 | +/** | |
| 425 | + * Function publishDocumentToWeb($DocumentID,$DTime) | |
| 426 | + * | |
| 427 | + * This function changes the publication status of a document to the WEB..ie it | |
| 428 | + * has received the required approval so its status has to change | |
| 429 | + * The web_documents table is update with The status id corresponding to the 'Published' | |
| 430 | + * Status and the DateTime is updated as well | |
| 431 | + * | |
| 432 | + * @param $DocumentID | |
| 433 | + * The id of the document that we wish to publish | |
| 434 | + * @param $DTime | |
| 435 | + * The Date and Time that the document was uploaded for publication | |
| 436 | + * or approval was given | |
| 437 | + * | |
| 438 | +*/ | |
| 439 | +//------------------------------------------------------------ | |
| 440 | +function publishDocumentToWeb($DocumentID,$DTime) | |
| 441 | +{ | |
| 442 | + | |
| 443 | + global $default; | |
| 444 | + $db = new Owl_DB(); | |
| 445 | + | |
| 446 | + // need to determine if a document has been published to the web already | |
| 447 | + $Sql = "SELECT status_id FROM " . $default->owl_web_documents_table . " WHERE document_id = $DocumentID"; | |
| 448 | + $result = $db->query($Sql); | |
| 449 | + $row = $db->num_rows($result); | |
| 450 | + $db->next_record(); | |
| 451 | + $isAlreadyPublishedID = $db->f("status_id"); | |
| 452 | + | |
| 453 | + // get id where name is Published (to prevent errors from change of id) | |
| 454 | + $Sql2 = "SELECT id FROM " . $default->owl_web_documents_status_table . " WHERE name = 'Published'"; | |
| 455 | + $published = $db->query($Sql2); | |
| 456 | + $db->next_record(); | |
| 457 | + $publishID = $db->f("id"); | |
| 458 | + | |
| 459 | + // make sure entry exists and then check status | |
| 460 | + if($row == 1) | |
| 461 | + { | |
| 462 | + if($isAlreadyPublishedID == $publishID) | |
| 463 | + { | |
| 464 | + | |
| 465 | + printf("\nDocument already published"); | |
| 466 | + return false; | |
| 467 | + } | |
| 468 | + | |
| 469 | + Else | |
| 470 | + { //status is pending..therefore update it to published | |
| 471 | + $Sql = "UPDATE " . $default->owl_web_documents_table . " SET status_id = $publishID, datetime = '$DTime' WHERE document_id = $DocumentID"; | |
| 472 | + $result = $db->query($Sql) ; | |
| 473 | + return true; | |
| 474 | + } | |
| 475 | + } | |
| 476 | + Else | |
| 477 | + { | |
| 478 | + printf("Document is not yet been sent for Publication approval"); | |
| 479 | + } | |
| 480 | +} | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 278 | 485 | |
| 279 | 486 | } |
| 280 | 487 | ?> | ... | ... |