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
00035 require_once "class.ilObject.php";
00036 require_once "./classes/class.ilFileDataExercise.php";
00037 require_once "./classes/class.ilExerciseMembers.php";
00038
00039
00040 class ilObjExercise extends ilObject
00041 {
00042 var $file_obj;
00043 var $members_obj;
00044 var $files;
00045
00046 var $timestamp;
00047 var $day;
00048 var $month;
00049 var $year;
00050 var $instruction;
00051
00058 function ilObjExercise($a_id = 0,$a_call_by_reference = true)
00059 {
00060 $this->type = "exc";
00061 $this->ilObject($a_id,$a_call_by_reference);
00062 }
00063
00064
00065 function setDate($a_day,$a_month,$a_year)
00066 {
00067 $this->day = (int) $a_day;
00068 $this->month = (int) $a_month;
00069 $this->year = (int) $a_year;
00070 $this->timestamp = mktime(0,0,0,$this->month,$this->day,$this->year);
00071 return true;
00072 }
00073 function getTimestamp()
00074 {
00075 return $this->timestamp;
00076 }
00077 function setTimestamp($a_timestamp)
00078 {
00079 $this->timestamp = $a_timestamp;
00080 }
00081 function setInstruction($a_instruction)
00082 {
00083 $this->instruction = $a_instruction;
00084 }
00085 function getInstruction()
00086 {
00087 return $this->instruction;
00088 }
00089 function getFiles()
00090 {
00091 return $this->files;
00092 }
00093
00094 function checkDate()
00095 {
00096 return $this->day == (int) date("d",$this->timestamp) and
00097 $this->month == (int) date("m",$this->timestamp) and
00098 $this->year == (int) date("Y",$this->timestamp);
00099 }
00100
00101 function deliverFile($a_http_post_files, $user_id)
00102 {
00103 $deliver_result = $this->file_obj->deliverFile($a_http_post_files, $user_id);
00104 if ($deliver_result)
00105 {
00106 $query = sprintf("INSERT INTO exc_returned (returned_id, obj_id, user_id, filename, filetitle, mimetype, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, %s, NULL)",
00107 $this->ilias->db->quote($this->getId() . ""),
00108 $this->ilias->db->quote($user_id . ""),
00109 $this->ilias->db->quote($deliver_result["fullname"]),
00110 $this->ilias->db->quote($a_http_post_files["name"]),
00111 $this->ilias->db->quote($deliver_result["mimetype"])
00112 );
00113 $this->ilias->db->query($query);
00114 if (!$this->members_obj->isAssigned($user_id))
00115 {
00116 $this->members_obj->assignMember($user_id);
00117 }
00118 $this->members_obj->setStatusReturnedForMember($user_id, 1);
00119 }
00120 return true;
00121 }
00122
00123 function addUploadedFile($a_http_post_files)
00124 {
00125 $this->file_obj->storeUploadedFile($a_http_post_files, true);
00126
00127 return true;
00128 }
00129 function deleteFiles($a_files)
00130 {
00131 $this->file_obj->unlinkFiles($a_files);
00132 }
00133
00134 function saveData()
00135 {
00136
00137
00138 $query = "INSERT INTO exc_data SET ".
00139 "obj_id = '".$this->getId()."', ".
00140 "instruction = '".addslashes($this->getInstruction())."', ".
00141 "time_stamp = ".$this->getTimestamp();
00142 $this->ilias->db->query($query);
00143 return true;
00144 }
00145
00152 function ilClone($a_parent_ref)
00153 {
00154 global $rbacadmin;
00155
00156
00157 $new_ref_id = parent::ilClone($a_parent_ref);
00158
00159
00160 $tmp_obj =& $this->ilias->obj_factory->getInstanceByRefId($new_ref_id);
00161 $tmp_obj->setInstruction($this->getInstruction());
00162 $tmp_obj->setTimestamp($this->getTimestamp());
00163 $tmp_obj->saveData();
00164
00165
00166 $tmp_file_obj =& new ilFileDataExercise($this->getId());
00167 $tmp_file_obj->ilClone($tmp_obj->getId());
00168
00169
00170 $tmp_members_obj =& new ilExerciseMembers($this->getId(),$new_ref_id);
00171 $tmp_members_obj->ilClone($tmp_obj->getId());
00172
00173
00174 return $new_ref_id;
00175 }
00176
00183 function &getDeliveredFiles($user_id)
00184 {
00185 $delivered_files =& $this->members_obj->getDeliveredFiles($user_id);
00186 return $delivered_files;
00187 }
00188
00195 function deleteDeliveredFiles($file_id_array, $user_id)
00196 {
00197 $this->members_obj->deleteDeliveredFiles($file_id_array, $user_id);
00198 }
00199
00205 function deliverReturnedFiles($user_id)
00206 {
00207 require_once "./classes/class.ilUtil.php";
00208 }
00209
00216 function delete()
00217 {
00218
00219 if (!parent::delete())
00220 {
00221 return false;
00222 }
00223
00224 $query = "DELETE FROM exc_data ".
00225 "WHERE obj_id = '".$this->getId()."'";
00226
00227 $this->ilias->db->query($query);
00228
00229 $this->file_obj->delete();
00230 $this->members_obj->delete();
00231
00232 return true;
00233 }
00234
00245 function notify($a_event,$a_ref_id,$a_node_id,$a_params = 0)
00246 {
00247
00248
00249 parent::notify($a_event,$a_ref_id,$a_node_id,$a_params);
00250 }
00251
00252 function read()
00253 {
00254 parent::read();
00255
00256 $query = "SELECT * FROM exc_data ".
00257 "WHERE obj_id = '".$this->getId()."'";
00258
00259 $res = $this->ilias->db->query($query);
00260 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00261 {
00262 $this->setInstruction($row->instruction);
00263 $this->setTimestamp($row->time_stamp);
00264 }
00265 $this->members_obj =& new ilExerciseMembers($this->getId(),$this->getRefId());
00266 $this->members_obj->read();
00267
00268
00269 $this->file_obj = new ilFileDataExercise($this->getId());
00270 $this->files = $this->file_obj->getFiles();
00271
00272 return true;
00273 }
00274
00275 function update()
00276 {
00277 parent::update();
00278
00279 $query = "UPDATE exc_data SET ".
00280 "instruction = '".addslashes($this->getInstruction())."', ".
00281 "time_stamp = '".$this->getTimestamp()."' ".
00282 "WHERE obj_id = '".$this->getId()."'";
00283
00284 $res = $this->ilias->db->query($query);
00285
00286 #$this->members_obj->update();
00287 return true;
00288 }
00289
00290 function send($a_members)
00291 {
00292 $files = $this->file_obj->getFiles();
00293 if(count($files))
00294 {
00295 include_once "./classes/class.ilFileDataMail.php";
00296
00297 $mfile_obj = new ilFileDataMail($_SESSION["AccountId"]);
00298 foreach($files as $file)
00299 {
00300 $mfile_obj->copyAttachmentFile($this->file_obj->getAbsolutePath($file["name"]),$file["name"]);
00301 $file_names[] = $file["name"];
00302 }
00303 }
00304
00305 include_once "./classes/class.ilMail.php";
00306
00307 $tmp_mail_obj = new ilMail($_SESSION["AccountId"]);
00308 $message = $tmp_mail_obj->sendMail($this->__formatRecipients($a_members),"","",$this->__formatSubject(),$this->__formatBody(),
00309 count($file_names) ? $file_names : array(),array("normal"));
00310
00311 unset($tmp_mail_obj);
00312
00313 if(count($file_names))
00314 {
00315 $mfile_obj->unlinkFiles($file_names);
00316 unset($mfile_obj);
00317 }
00318
00319
00320
00321 foreach($a_members as $member_id => $value)
00322 {
00323 $this->members_obj->setStatusSentForMember($member_id,1);
00324 }
00325
00326 return true;
00327 }
00328
00329
00330
00331 function __formatBody()
00332 {
00333 global $lng;
00334
00335 $body = $this->getInstruction();
00336 $body .= "\n";
00337 $body .= $lng->txt("exc_edit_until") . ": ".date("Y-m-d",$this->getTimestamp());
00338
00339 return $body;
00340 }
00341
00342 function __formatSubject()
00343 {
00344 return $subject = $this->getTitle()." (".$this->getDescription().")";
00345 }
00346
00347 function __formatRecipients($a_members)
00348 {
00349 foreach($a_members as $member_id => $value)
00350 {
00351 $tmp_obj = ilObjectFactory::getInstanceByObjId($member_id);
00352 $tmp_members[] = $tmp_obj->getLogin();
00353
00354 unset($tmp_obj);
00355 }
00356
00357 return implode(',',$tmp_members ? $tmp_members : array());
00358 }
00359
00360 function _checkCondition($a_exc_id,$a_operator,$a_value)
00361 {
00362 global $ilias;
00363
00364 switch($a_operator)
00365 {
00366 case 'passed':
00367 return ilExerciseMembers::_hasSolved($a_exc_id,$ilias->account->getId());
00368
00369 default:
00370 return true;
00371 }
00372 return true;
00373 }
00374
00380 function _goto($a_target)
00381 {
00382 global $rbacsystem, $ilErr, $lng;
00383
00384 include_once 'classes/class.ilSearch.php';
00385
00386
00387
00388 if ($rbacsystem->checkAccess("read", $a_target) and ilSearch::_checkParentConditions($a_target))
00389 {
00390 ilUtil::redirect("exercise.php?ref_id=$a_target");
00391 }
00392 else
00393 {
00394 $ilErr->raiseError($lng->txt("msg_no_perm_read_lm"), $ilErr->FATAL);
00395 }
00396 }
00397 }
00398 ?>