00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 require_once "classes/class.ilObject.php";
00025 require_once "./Modules/Exercise/classes/class.ilFileDataExercise.php";
00026 require_once "./Modules/Exercise/classes/class.ilExerciseMembers.php";
00027
00039 class ilObjExercise extends ilObject
00040 {
00041 var $file_obj;
00042 var $members_obj;
00043 var $files;
00044
00045 var $timestamp;
00046 var $hour;
00047 var $minutes;
00048 var $day;
00049 var $month;
00050 var $year;
00051 var $instruction;
00052
00059 function ilObjExercise($a_id = 0,$a_call_by_reference = true)
00060 {
00061 $this->type = "exc";
00062 $this->ilObject($a_id,$a_call_by_reference);
00063 }
00064
00065
00066 function setDate($a_hour,$a_minutes,$a_day,$a_month,$a_year)
00067 {
00068 $this->hour = (int) $a_hour;
00069 $this->minutes = (int) $a_minutes;
00070 $this->day = (int) $a_day;
00071 $this->month = (int) $a_month;
00072 $this->year = (int) $a_year;
00073 $this->timestamp = mktime($this->hour,$this->minutes,0,$this->month,$this->day,$this->year);
00074 return true;
00075 }
00076 function getTimestamp()
00077 {
00078 return $this->timestamp;
00079 }
00080 function setTimestamp($a_timestamp)
00081 {
00082 $this->timestamp = $a_timestamp;
00083 }
00084 function setInstruction($a_instruction)
00085 {
00086 $this->instruction = $a_instruction;
00087 }
00088 function getInstruction()
00089 {
00090 return $this->instruction;
00091 }
00092 function getFiles()
00093 {
00094 return $this->files;
00095 }
00096
00097 function checkDate()
00098 {
00099 return $this->hour == (int) date("H",$this->timestamp) and
00100 $this->minutes == (int) date("i",$this->timestamp) and
00101 $this->day == (int) date("d",$this->timestamp) and
00102 $this->month == (int) date("m",$this->timestamp) and
00103 $this->year == (int) date("Y",$this->timestamp);
00104
00105 }
00106
00107 function deliverFile($a_http_post_files, $user_id, $unzip = false)
00108 {
00109 $deliver_result = $this->file_obj->deliverFile($a_http_post_files, $user_id, $unzip);
00110
00111 if ($deliver_result)
00112 {
00113 $query = sprintf("INSERT INTO exc_returned ".
00114 "(returned_id, obj_id, user_id, filename, filetitle, mimetype, TIMESTAMP) ".
00115 "VALUES (NULL, %s, %s, %s, %s, %s, NULL)",
00116 $this->ilias->db->quote($this->getId() . ""),
00117 $this->ilias->db->quote($user_id . ""),
00118 $this->ilias->db->quote($deliver_result["fullname"]),
00119 $this->ilias->db->quote($a_http_post_files["name"]),
00120 $this->ilias->db->quote($deliver_result["mimetype"])
00121 );
00122 $this->ilias->db->query($query);
00123 if (!$this->members_obj->isAssigned($user_id))
00124 {
00125 $this->members_obj->assignMember($user_id);
00126 }
00127 $this->members_obj->setStatusReturnedForMember($user_id, 1);
00128 }
00129 return true;
00130 }
00131
00132 function addUploadedFile($a_http_post_files, $unzipUploadedFile = false)
00133 {
00134 global $lng;
00135 if ($unzipUploadedFile && preg_match("/zip/", $a_http_post_files["type"]) == 1)
00136 {
00137
00138 $this->processUploadedFile($a_http_post_files["tmp_name"], "storeUploadedFile", true);
00139 return true;
00140
00141
00142 }
00143 else
00144 {
00145 $this->file_obj->storeUploadedFile($a_http_post_files, true);
00146 return true;
00147 }
00148 }
00149 function deleteFiles($a_files)
00150 {
00151 $this->file_obj->unlinkFiles($a_files);
00152 }
00153
00154 function saveData()
00155 {
00156 global $ilDB;
00157
00158
00159 $query = "INSERT INTO exc_data SET ".
00160 "obj_id = ".$ilDB->quote($this->getId()).", ".
00161 "instruction = ".$ilDB->quote($this->getInstruction()).", ".
00162 "time_stamp = ".$ilDB->quote($this->getTimestamp());
00163 $this->ilias->db->query($query);
00164 return true;
00165 }
00166
00174 public function cloneObject($a_target_id,$a_copy_id = 0)
00175 {
00176 global $ilDB;
00177
00178
00179 $new_obj = parent::cloneObject($a_target_id,$a_copy_id);
00180 $new_obj->setInstruction($this->getInstruction());
00181 $new_obj->setTimestamp($this->getTimestamp());
00182 $new_obj->saveData();
00183
00184
00185 $tmp_file_obj =& new ilFileDataExercise($this->getId());
00186 $tmp_file_obj->ilClone($new_obj->getId());
00187 unset($tmp_file_obj);
00188
00189
00190 include_once('Services/Tracking/classes/class.ilLPObjSettings.php');
00191 $obj_settings = new ilLPObjSettings($this->getId());
00192 $obj_settings->cloneSettings($new_obj->getId());
00193 unset($obj_settings);
00194
00195 return $new_obj;
00196 }
00197
00198
00205 function &getDeliveredFiles($user_id)
00206 {
00207 $delivered_files =& $this->members_obj->getDeliveredFiles($user_id);
00208 return $delivered_files;
00209 }
00210
00217 function deleteDeliveredFiles($file_id_array, $user_id)
00218 {
00219 $this->members_obj->deleteDeliveredFiles($file_id_array, $user_id);
00220
00221
00222 if(!count($this->members_obj->getDeliveredFiles($user_id)))
00223 {
00224 $this->members_obj->setStatusReturnedForMember($user_id,0);
00225 }
00226
00227 }
00228
00234 function deliverReturnedFiles($user_id)
00235 {
00236 require_once "./Services/Utilities/classes/class.ilUtil.php";
00237 }
00238
00245 function delete()
00246 {
00247 global $ilDB;
00248
00249
00250 if (!parent::delete())
00251 {
00252 return false;
00253 }
00254
00255 $query = "DELETE FROM exc_data ".
00256 "WHERE obj_id = ".$ilDB->quote($this->getId());
00257
00258 $this->ilias->db->query($query);
00259
00260 $this->file_obj->delete();
00261 $this->members_obj->delete();
00262
00263 return true;
00264 }
00265
00276 function notify($a_event,$a_ref_id,$a_node_id,$a_params = 0)
00277 {
00278
00279
00280 parent::notify($a_event,$a_ref_id,$a_node_id,$a_params);
00281 }
00282
00283 function read()
00284 {
00285 global $ilDB;
00286
00287 parent::read();
00288
00289 $query = "SELECT * FROM exc_data ".
00290 "WHERE obj_id = ".$ilDB->quote($this->getId());
00291
00292 $res = $this->ilias->db->query($query);
00293 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00294 {
00295 $this->setInstruction($row->instruction);
00296 $this->setTimestamp($row->time_stamp);
00297 }
00298 $this->members_obj =& new ilExerciseMembers($this->getId(),$this->getRefId());
00299 $this->members_obj->read();
00300
00301
00302 $this->file_obj = new ilFileDataExercise($this->getId());
00303 $this->files = $this->file_obj->getFiles();
00304
00305 return true;
00306 }
00307
00308 function update()
00309 {
00310 global $ilDB;
00311
00312 parent::update();
00313
00314 $query = "UPDATE exc_data SET ".
00315 "instruction = ".$ilDB->quote($this->getInstruction()).", ".
00316 "time_stamp = ".$ilDB->quote($this->getTimestamp())." ".
00317 "WHERE obj_id = ".$ilDB->quote($this->getId());
00318
00319 $res = $this->ilias->db->query($query);
00320
00321 #$this->members_obj->update();
00322 return true;
00323 }
00324
00328 function getMemberListData()
00329 {
00330 global $ilDB;
00331
00332 $mem = array();
00333 $q = "SELECT * FROM exc_members ".
00334 "WHERE obj_id = ".$ilDB->quote($this->getId());
00335 $set = $ilDB->query($q);
00336 while($rec = $set->fetchRow(DB_FETCHMODE_ASSOC))
00337 {
00338 if (ilObject::_exists($rec["usr_id"]) &&
00339 (ilObject::_lookupType($rec["usr_id"]) == "usr"))
00340 {
00341 $name = ilObjUser::_lookupName($rec["usr_id"]);
00342 $login = ilObjUser::_lookupLogin($rec["usr_id"]);
00343 $mem[] =
00344 array("name" => $name["lastname"].", ".$name["firstname"],
00345 "login" => $login,
00346 "sent_time" => $rec["sent_time"],
00347 "submission" => $this->getLastSubmission($rec["usr_id"]),
00348 "status_time" => $rec["status_time"],
00349 "feedback_time" => $rec["feedback_time"],
00350 "usr_id" => $rec["usr_id"]
00351 );
00352 }
00353 }
00354 return $mem;
00355 }
00356
00363 function getLastSubmission($member_id)
00364 {
00365 global $ilDB, $lng;
00366
00367 $q="SELECT obj_id,user_id,timestamp FROM exc_returned ".
00368 "WHERE obj_id =".$ilDB->quote($this->getId())." AND user_id=".
00369 $ilDB->quote($member_id).
00370 " ORDER BY timestamp DESC";
00371
00372 $usr_set = $ilDB->query($q);
00373
00374 $array=$usr_set->fetchRow(DB_FETCHMODE_ASSOC);
00375 if ($array["timestamp"]==NULL)
00376 {
00377 return false;
00378 }
00379 else
00380 {
00381 return ilUtil::getMySQLTimestamp($array["timestamp"]);
00382 }
00383 }
00384
00388 function send($a_members)
00389 {
00390 $files = $this->file_obj->getFiles();
00391 if(count($files))
00392 {
00393 include_once "./classes/class.ilFileDataMail.php";
00394
00395 $mfile_obj = new ilFileDataMail($_SESSION["AccountId"]);
00396 foreach($files as $file)
00397 {
00398 $mfile_obj->copyAttachmentFile($this->file_obj->getAbsolutePath($file["name"]),$file["name"]);
00399 $file_names[] = $file["name"];
00400 }
00401 }
00402
00403 include_once "Services/Mail/classes/class.ilMail.php";
00404
00405 $tmp_mail_obj = new ilMail($_SESSION["AccountId"]);
00406 $message = $tmp_mail_obj->sendMail($this->__formatRecipients($a_members),"","",$this->__formatSubject(),$this->__formatBody(),
00407 count($file_names) ? $file_names : array(),array("normal"));
00408
00409 unset($tmp_mail_obj);
00410
00411 if(count($file_names))
00412 {
00413 $mfile_obj->unlinkFiles($file_names);
00414 unset($mfile_obj);
00415 }
00416
00417
00418
00419 foreach($a_members as $member_id => $value)
00420 {
00421 $this->members_obj->setStatusSentForMember($member_id,1);
00422 }
00423
00424 return true;
00425 }
00426
00431 function _lookupUpdatedSubmission($exc_id, $member_id)
00432 {
00433
00434 global $ilDB, $lng;
00435
00436 $q="SELECT exc_members.status_time, exc_returned.timestamp ".
00437 "FROM exc_members, exc_returned ".
00438 "WHERE exc_members.status_time < exc_returned.timestamp ".
00439 "AND exc_members.status_time <> '0000-00-00 00:00:00' ".
00440 "AND exc_returned.obj_id = exc_members.obj_id ".
00441 "AND exc_returned.user_id = exc_members.usr_id ".
00442 "AND exc_returned.obj_id=".$ilDB->quote($exc_id)." AND exc_returned.user_id=".
00443 $ilDB->quote($member_id);
00444
00445 $usr_set = $ilDB->query($q);
00446
00447 $array=$usr_set->fetchRow(DB_FETCHMODE_ASSOC);
00448
00449 if (count($array)==0)
00450 {
00451 return 0;
00452 }
00453 else
00454 {
00455 return 1;
00456 }
00457
00458 }
00459
00460
00464 function _lookupAnyExerciseSent($a_exc_id)
00465 {
00466 global $ilDB;
00467
00468 $q = "SELECT count(*) AS cnt FROM exc_members".
00469 " WHERE sent_time <> '0000-00-00 00:00:00'".
00470 " AND obj_id = ".$ilDB->quote($a_exc_id);
00471 $set = $ilDB->query($q);
00472 $rec = $set->fetchRow(DB_FETCHMODE_ASSOC);
00473
00474 if ($rec["cnt"] > 0)
00475 {
00476 return true;
00477 }
00478 else
00479 {
00480 return false;
00481 }
00482 }
00483
00488 function _lookupNewFiles($exc_id, $member_id)
00489 {
00490 global $ilDB, $ilUser;
00491
00492 $q = "SELECT exc_returned.returned_id AS id ".
00493 "FROM exc_usr_tutor, exc_returned ".
00494 "WHERE exc_returned.obj_id = exc_usr_tutor.obj_id ".
00495 "AND exc_returned.user_id = exc_usr_tutor.usr_id ".
00496 "AND exc_returned.obj_id = ".$ilDB->quote($exc_id).
00497 "AND exc_returned.user_id = ".$ilDB->quote($member_id).
00498 "AND exc_usr_tutor.tutor_id = ".$ilDB->quote($ilUser->getId()).
00499 "AND exc_usr_tutor.download_time < exc_returned.timestamp ";
00500
00501 $new_up_set = $ilDB->query($q);
00502
00503 $new_up = array();
00504 while ($new_up_rec = $new_up_set->fetchRow(DB_FETCHMODE_ASSOC))
00505 {
00506 $new_up[] = $new_up_rec["id"];
00507 }
00508
00509 return $new_up;
00510 }
00511
00515 function _lookupStatusTime($exc_id, $member_id)
00516 {
00517
00518 global $ilDB, $lng;
00519
00520 $q = "SELECT * ".
00521 "FROM exc_members ".
00522 "WHERE obj_id= ".$ilDB->quote($exc_id)." AND usr_id= ".$ilDB->quote($member_id);
00523
00524 $set = $ilDB->query($q);
00525 if ($rec = $set->fetchRow(DB_FETCHMODE_ASSOC))
00526 {
00527 return ilUtil::getMySQLTimestamp($rec["status_time"]);
00528 }
00529 }
00530
00534 function _lookupSentTime($exc_id, $member_id)
00535 {
00536
00537 global $ilDB, $lng;
00538
00539 $q = "SELECT * ".
00540 "FROM exc_members ".
00541 "WHERE obj_id= ".$ilDB->quote($exc_id)." AND usr_id= ".$ilDB->quote($member_id);
00542
00543 $set = $ilDB->query($q);
00544 if ($rec = $set->fetchRow(DB_FETCHMODE_ASSOC))
00545 {
00546 return ilUtil::getMySQLTimestamp($rec["sent_time"]);
00547 }
00548 }
00549
00553 function _lookupFeedbackTime($exc_id, $member_id)
00554 {
00555
00556 global $ilDB, $lng;
00557
00558 $q = "SELECT * ".
00559 "FROM exc_members ".
00560 "WHERE obj_id= ".$ilDB->quote($exc_id)." AND usr_id= ".$ilDB->quote($member_id);
00561
00562 $set = $ilDB->query($q);
00563 if ($rec = $set->fetchRow(DB_FETCHMODE_ASSOC))
00564 {
00565 return ilUtil::getMySQLTimestamp($rec["feedback_time"]);
00566 }
00567 }
00568
00569
00570 function __formatBody()
00571 {
00572 global $lng;
00573
00574 $body = $this->getInstruction();
00575 $body .= "\n\n";
00576 $body .= $lng->txt("exc_edit_until") . ": ".
00577 ilFormat::formatDate(date("Y-m-d H:i:s",$this->getTimestamp()), "datetime", true);
00578 $body .= "\n\n";
00579 $body .= ILIAS_HTTP_PATH.
00580 "/goto.php?target=".
00581 $this->getType().
00582 "_".$this->getRefId()."&client_id=".CLIENT_ID;
00583
00584 return $body;
00585 }
00586
00587 function __formatSubject()
00588 {
00589 return $subject = $this->getTitle()." (".$this->getDescription().")";
00590 }
00591
00592 function __formatRecipients($a_members)
00593 {
00594 foreach($a_members as $member_id => $value)
00595 {
00596 $tmp_obj = ilObjectFactory::getInstanceByObjId($member_id);
00597 $tmp_members[] = $tmp_obj->getLogin();
00598
00599 unset($tmp_obj);
00600 }
00601
00602 return implode(',',$tmp_members ? $tmp_members : array());
00603 }
00604
00605 function _checkCondition($a_exc_id,$a_operator,$a_value)
00606 {
00607 global $ilias;
00608
00609 switch($a_operator)
00610 {
00611 case 'passed':
00612 if (ilExerciseMembers::_lookupStatus($a_exc_id, $ilias->account->getId()) == "passed")
00613 {
00614 return true;
00615 }
00616 else
00617 {
00618 return false;
00619 }
00620 break;
00621
00622 default:
00623 return true;
00624 }
00625 return true;
00626 }
00627
00634 function processUploadedFile ($fileTmp, $storageMethod, $persistentErrorMessage)
00635 {
00636 global $lng, $ilUser;
00637
00638
00639 $newDir = ilUtil::ilTempnam();
00640 ilUtil::makeDir($newDir);
00641
00642 include_once ("Services/Utilities/classes/class.ilFileUtils.php");
00643
00644 try
00645 {
00646 $processDone = ilFileUtils::processZipFile($newDir,$fileTmp, false);
00647 ilFileUtils::recursive_dirscan($newDir, $filearray);
00648
00649 foreach ($filearray["file"] as $key => $filename)
00650 {
00651 $a_http_post_files["name"] = $filename;
00652 $a_http_post_files["type"] = "other";
00653 $a_http_post_files["tmp_name"] = $filearray["path"][$key]."/".$filename;
00654 $a_http_post_files["error"] = 0;
00655 $a_http_post_files["size"] = filesize($filearray["path"][$key]."/".$filename);
00656
00657 if ($storageMethod == "deliverFile")
00658 {
00659 $this->$storageMethod($a_http_post_files, $ilUser->id, true);
00660 }
00661 else if ($storageMethod == "storeUploadedFile")
00662 {
00663 $this->file_obj->$storageMethod($a_http_post_files, true, true);
00664 }
00665 }
00666 ilUtil::sendInfo($this->lng->txt("file_added"),$persistentErrorMessage);
00667
00668 }
00669 catch (ilFileUtilsException $e)
00670 {
00671 ilUtil::sendInfo($e->getMessage(), $persistentErrorMessage);
00672 }
00673
00674
00675 ilUtil::delDir($newDir);
00676 return $processDone;
00677
00678 }
00679
00680 }
00681 ?>