ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilSoapCourseAdministration.php
Go to the documentation of this file.
1 <?php
2  /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22  */
23 
24 
33 include_once './webservice/soap/classes/class.ilSoapAdministration.php';
34 
36 {
37  const MEMBER = 1;
38  const TUTOR = 2;
39  const ADMIN = 4;
40  const OWNER = 8;
41 
43  {
45  }
46 
47 
48  // Service methods
49  function addCourse($sid,$target_id,$crs_xml)
50  {
51  $this->initAuth($sid);
52  $this->initIlias();
53 
54  if(!$this->__checkSession($sid))
55  {
56  return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
57  }
58 
59  if(!is_numeric($target_id))
60  {
61  return $this->__raiseError('No valid target id given. Please choose an existing reference id of an ILIAS category',
62  'Client');
63  }
64 
65  global $rbacsystem;
66 
67  if(!$target_obj =& ilObjectFactory::getInstanceByRefId($target_id, false))
68  {
69  return $this->__raiseError('No valid target given.', 'Client');
70  }
71 
73  {
74  return $this->__raiseError("Parent with ID $target_id has been deleted.", 'CLIENT_OBJECT_DELETED');
75  }
76 
77  if(!$rbacsystem->checkAccess('create',$target_id,'crs'))
78  {
79  return $this->__raiseError('Check access failed. No permission to create courses','Server');
80  }
81 
82 
83  // Start import
84  include_once("Modules/Course/classes/class.ilObjCourse.php");
85 
86  $newObj = new ilObjCourse();
87  $newObj->setType('crs');
88  $newObj->setTitle('dummy');
89  $newObj->setDescription("");
90  $newObj->create(true); // true for upload
91  $newObj->createReference();
92  $newObj->putInTree($target_id);
93  $newObj->setPermissions($target_id);
94  $newObj->initDefaultRoles();
95 
96  include_once 'Modules/Course/classes/class.ilCourseXMLParser.php';
97 
98  $xml_parser = new ilCourseXMLParser($newObj);
99  $xml_parser->setXMLContent($crs_xml);
100  $xml_parser->startParsing();
101  return $newObj->getRefId() ? $newObj->getRefId() : "0";
102 
103  }
104 
105  function deleteCourse($sid,$course_id)
106  {
107  $this->initAuth($sid);
108  $this->initIlias();
109 
110  if(!$this->__checkSession($sid))
111  {
112  return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
113  }
114 
115  if(!is_numeric($course_id))
116  {
117  return $this->__raiseError('No valid course id given. Please choose an existing reference id of an ILIAS course',
118  'Client');
119  }
120 
121  include_once "./Services/Utilities/classes/class.ilUtil.php";
122  global $rbacsystem;
123 
124  if(($obj_type = ilObject::_lookupType(ilObject::_lookupObjId($course_id))) != 'crs')
125  {
126  $course_id = end($ref_ids = ilObject::_getAllReferences($course_id));
127  if(ilObject::_lookupType(ilObject::_lookupObjId($course_id)) != 'crs')
128  {
129  return $this->__raiseError('Invalid course id. Object with id "'. $course_id.'" is not of type "course"','Client');
130  }
131  }
132 
133  if(!$rbacsystem->checkAccess('delete',$course_id))
134  {
135  return $this->__raiseError('Check access failed. No permission to delete course','Server');
136  }
137 
138 
139  global $tree,$rbacadmin,$log;
140 
141  if($tree->isDeleted($course_id))
142  {
143  return $this->__raiseError('Node already deleted','Server');
144  }
145 
146  $subnodes = $tree->getSubtree($tree->getNodeData($course_id));
147  foreach ($subnodes as $subnode)
148  {
149  $rbacadmin->revokePermission($subnode["child"]);
150 
151  // remove item from all user desktops
152  $affected_users = ilUtil::removeItemFromDesktops($subnode["child"]);
153 
154  }
155  if(!$tree->saveSubTree($course_id))
156  {
157  return $this->__raiseError('Node already deleted','Client');
158  }
159 
160  // write log entry
161  $log->write("SOAP ilObjectGUI::confirmedDeleteObject(), moved ref_id ".$course_id." to trash");
162 
163  // remove item from all user desktops
164  $affected_users = ilUtil::removeItemFromDesktops($course_id);
165 
166  return true;
167  }
168 
169  function assignCourseMember($sid,$course_id,$user_id,$type)
170  {
171  $this->initAuth($sid);
172  $this->initIlias();
173 
174  if(!$this->__checkSession($sid))
175  {
176  return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
177  }
178 
179  if(!is_numeric($course_id))
180  {
181  return $this->__raiseError('No valid course id given. Please choose an existing reference id of an ILIAS course',
182  'Client');
183  }
184 
185  global $rbacsystem;
186 
187  if(($obj_type = ilObject::_lookupType(ilObject::_lookupObjId($course_id))) != 'crs')
188  {
189  $course_id = end($ref_ids = ilObject::_getAllReferences($course_id));
190  if(ilObject::_lookupType(ilObject::_lookupObjId($course_id)) != 'crs')
191  {
192  return $this->__raiseError('Invalid course id. Object with id "'. $course_id.'" is not of type "course"','Client');
193  }
194  }
195 
196  if(!$rbacsystem->checkAccess('write',$course_id))
197  {
198  return $this->__raiseError('Check access failed. No permission to write to course','Server');
199  }
200 
201 
202  if(ilObject::_lookupType($user_id) != 'usr')
203  {
204  return $this->__raiseError('Invalid user id. User with id "'. $user_id.' does not exist','Client');
205  }
206  if($type != 'Admin' and
207  $type != 'Tutor' and
208  $type != 'Member')
209  {
210  return $this->__raiseError('Invalid type given. Parameter "type" must be "Admin", "Tutor" or "Member"','Client');
211  }
212 
213  if(!$tmp_course = ilObjectFactory::getInstanceByRefId($course_id,false))
214  {
215  return $this->__raiseError('Cannot create course instance!','Server');
216  }
217 
218  if(!$tmp_user = ilObjectFactory::getInstanceByObjId($user_id,false))
219  {
220  return $this->__raiseError('Cannot create user instance!','Server');
221  }
222 
223  include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
224 
225  $course_members = ilCourseParticipants::_getInstanceByObjId($tmp_course->getId());
226 
227  switch($type)
228  {
229  case 'Admin':
230  $course_members->add($tmp_user->getId(),IL_CRS_ADMIN);
231  $course_members->updateNotification($tmp_user->getId(),1);
232  break;
233 
234  case 'Tutor':
235  $course_members->add($tmp_user->getId(),IL_CRS_TUTOR);
236  break;
237 
238  case 'Member':
239  $course_members->add($tmp_user->getId(),IL_CRS_MEMBER);
240  break;
241  }
242 
243  return true;
244  }
245 
246  function excludeCourseMember($sid,$course_id,$user_id)
247  {
248  $this->initAuth($sid);
249  $this->initIlias();
250 
251  if(!$this->__checkSession($sid))
252  {
253  return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
254  }
255  if(!is_numeric($course_id))
256  {
257  return $this->__raiseError('No valid course id given. Please choose an existing reference id of an ILIAS course',
258  'Client');
259  }
260 
261  global $rbacsystem;
262 
263  if(($obj_type = ilObject::_lookupType(ilObject::_lookupObjId($course_id))) != 'crs')
264  {
265  $course_id = end($ref_ids = ilObject::_getAllReferences($course_id));
266  if(ilObject::_lookupType(ilObject::_lookupObjId($course_id)) != 'crs')
267  {
268  return $this->__raiseError('Invalid course id. Object with id "'. $course_id.'" is not of type "course"','Client');
269  }
270  }
271 
272  if(ilObject::_lookupType($user_id) != 'usr')
273  {
274  return $this->__raiseError('Invalid user id. User with id "'. $user_id.' does not exist','Client');
275  }
276 
277  if(!$tmp_course = ilObjectFactory::getInstanceByRefId($course_id,false))
278  {
279  return $this->__raiseError('Cannot create course instance!','Server');
280  }
281 
282  if(!$rbacsystem->checkAccess('write',$course_id))
283  {
284  return $this->__raiseError('Check access failed. No permission to write to course','Server');
285  }
286 
287  include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
288 
289  $course_members = ilCourseParticipants::_getInstanceByObjId($tmp_course->getId());
290  if(!$course_members->checkLastAdmin(array($user_id)))
291  {
292  return $this->__raiseError('Cannot deassign last administrator from course','Server');
293  }
294 
295  $course_members->delete($user_id);
296 
297  return true;
298  }
299 
300 
301  function isAssignedToCourse($sid,$course_id,$user_id)
302  {
303  $this->initAuth($sid);
304  $this->initIlias();
305 
306  if(!$this->__checkSession($sid))
307  {
308  return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
309  }
310  if(!is_numeric($course_id))
311  {
312  return $this->__raiseError('No valid course id given. Please choose an existing reference id of an ILIAS course',
313  'Client');
314  }
315  global $rbacsystem;
316 
317  if(($obj_type = ilObject::_lookupType(ilObject::_lookupObjId($course_id))) != 'crs')
318  {
319  $course_id = end($ref_ids = ilObject::_getAllReferences($course_id));
320  if(ilObject::_lookupType(ilObject::_lookupObjId($course_id)) != 'crs')
321  {
322  return $this->__raiseError('Invalid course id. Object with id "'. $course_id.'" is not of type "course"','Client');
323  }
324  }
325 
326  if(ilObject::_lookupType($user_id) != 'usr')
327  {
328  return $this->__raiseError('Invalid user id. User with id "'. $user_id.' does not exist','Client');
329  }
330 
331  if(!$tmp_course = ilObjectFactory::getInstanceByRefId($course_id,false))
332  {
333  return $this->__raiseError('Cannot create course instance!','Server');
334  }
335 
336  if(!$rbacsystem->checkAccess('write',$course_id))
337  {
338  return $this->__raiseError('Check access failed. No permission to write to course','Server');
339  }
340 
341  include_once './Modules/Course/classes/class.ilCourseParticipants.php';
342  $crs_members = ilCourseParticipants::_getInstanceByObjId($tmp_course->getId());
343 
344  if($crs_members->isAdmin($user_id))
345  {
346  return IL_CRS_ADMIN;
347  }
348  if($crs_members->isTutor($user_id))
349  {
350  return IL_CRS_TUTOR;
351  }
352  if($crs_members->isMember($user_id))
353  {
354  return IL_CRS_MEMBER;
355  }
356 
357  return "0";
358  }
359 
360 
361  function getCourseXML($sid,$course_id)
362  {
363  $this->initAuth($sid);
364  $this->initIlias();
365 
366  if(!$this->__checkSession($sid))
367  {
368  return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
369  }
370  if(!is_numeric($course_id))
371  {
372  return $this->__raiseError('No valid course id given. Please choose an existing reference id of an ILIAS course',
373  'Client');
374  }
375 
376  global $rbacsystem;
377 
378  $tmp_course = $this->checkObjectAccess($course_id, "crs", "read", true);
379  if ($this->isFault($tmp_course)) {
380  return $tmp_course;
381  }
382 
383  /*if(($obj_type = ilObject::_lookupType(ilObject::_lookupObjId($course_id))) != 'crs')
384  {
385  $course_id = end($ref_ids = ilObject::_getAllReferences($course_id));
386  if(ilObject::_lookupType(ilObject::_lookupObjId($course_id)) != 'crs')
387  {
388  return $this->__raiseError('Invalid course id. Object with id "'. $course_id.'" is not of type "course"','Client');
389  }
390  }
391 
392  if(!$tmp_course = ilObjectFactory::getInstanceByRefId($course_id,false))
393  {
394  return $this->__raiseError('Cannot create course instance!','Server');
395  }
396 
397  if(!$rbacsystem->checkAccess('read',$course_id))
398  {
399  return $this->__raiseError('Check access failed. No permission to read course','Server');
400  }*/
401 
402  include_once 'Modules/Course/classes/class.ilCourseXMLWriter.php';
403 
404  $xml_writer = new ilCourseXMLWriter($tmp_course);
405  $xml_writer->start();
406 
407  return $xml_writer->getXML();
408  }
409 
410  function updateCourse($sid,$course_id,$xml)
411  {
412  $this->initAuth($sid);
413  $this->initIlias();
414 
415  if(!$this->__checkSession($sid))
416  {
417  return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
418  }
419 
420  if(!is_numeric($course_id))
421  {
422  return $this->__raiseError('No valid course id given. Please choose an existing reference id of an ILIAS course',
423  'Client');
424  }
425 
426  global $rbacsystem;
427 
428  if(($obj_type = ilObject::_lookupType(ilObject::_lookupObjId($course_id))) != 'crs')
429  {
430  $course_id = end($ref_ids = ilObject::_getAllReferences($course_id));
431  if(ilObject::_lookupType(ilObject::_lookupObjId($course_id)) != 'crs')
432  {
433  return $this->__raiseError('Invalid course id. Object with id "'. $course_id.'" is not of type "course"','Client');
434  }
435  }
436 
437  if(!$tmp_course = ilObjectFactory::getInstanceByRefId($course_id,false))
438  {
439  return $this->__raiseError('Cannot create course instance!','Server');
440  }
441 
442  if(!$rbacsystem->checkAccess('write',$course_id))
443  {
444  return $this->__raiseError('Check access failed. No permission to write course','Server');
445  }
446 
447 
448  // First delete old meta data
449  include_once 'Services/MetaData/classes/class.ilMD.php';
450 
451  $md = new ilMD($tmp_course->getId(),0,'crs');
452  $md->deleteAll();
453 
454  include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
455  ilCourseParticipants::_deleteAllEntries($tmp_course->getId());
456 
457 
458  include_once 'Modules/Course/classes/class.ilCourseWaitingList.php';
459  ilCourseWaitingList::_deleteAll($tmp_course->getId());
460 
461  include_once 'Modules/Course/classes/class.ilCourseXMLParser.php';
462 
463  $xml_parser = new ilCourseXMLParser($tmp_course);
464  $xml_parser->setXMLContent($xml);
465 
466  $xml_parser->startParsing();
467 
468  $tmp_course->MDUpdateListener('General');
469 
470  return true;
471  }
472 
473  // PRIVATE
474 
482  function getCoursesForUser($sid, $parameters) {
483 
484  $this->initAuth($sid);
485  $this->initIlias();
486 
487  if(!$this->__checkSession($sid))
488  {
489  return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
490  }
491 
492  global $rbacreview, $ilObjDataCache, $tree;
493 
494  include_once 'webservice/soap/classes/class.ilXMLResultSetParser.php';
495  $parser = new ilXMLResultSetParser($parameters);
496  try {
497  $parser->startParsing();
498  } catch (ilSaxParserException $exception) {
499  return $this->__raiseError($exception->getMessage(), "Client");
500  }
501  $xmlResultSet = $parser->getXMLResultSet();
502 
503  if (!$xmlResultSet->hasColumn ("user_id"))
504  return $this->__raiseError("parameter user_id is missing", "Client");
505 
506  if (!$xmlResultSet->hasColumn ("status"))
507  return $this->__raiseError("parameter status is missing", "Client");
508 
509  $user_id = (int) $xmlResultSet->getValue (0, "user_id");
510  $status = (int) $xmlResultSet->getValue (0, "status");
511 
512  $ref_ids = array();
513 
514  // get roles
515 #var_dump($xmlResultSet);
516 #echo "uid:".$user_id;
517 #echo "status:".$status;
521  foreach($rbacreview->assignedRoles($user_id) as $role_id)
522  {
523  if($role = ilObjectFactory::getInstanceByObjId($role_id,false))
524  {
525  #echo $role->getType();
526  if ($role->getType() != "role")
527  continue;
528  if ($role->getParent() == ROLE_FOLDER_ID)
529  {
530  continue;
531  }
532  $role_title = $role->getTitle();
533 
534  if ($ref_id = ilUtil::__extractRefId($role_title))
535  {
537  continue;
538 
539  #echo $role_title;
540  if (ilSoapCourseAdministration::MEMBER == ($status & ilSoapCourseAdministration::MEMBER) && strpos($role_title, "member") !== false)
541  {
542  $ref_ids [] = $ref_id;
543  } elseif (ilSoapCourseAdministration::TUTOR == ($status & ilSoapCourseAdministration::TUTOR) && strpos($role_title, "tutor") !== false)
544  {
545  $ref_ids [] = $ref_id;
546  } elseif (ilSoapCourseAdministration::ADMIN == ($status & ilSoapCourseAdministration::ADMIN) && strpos($role_title, "admin") !== false)
547  {
548  $ref_ids [] = $ref_id;
549  } elseif (($status & ilSoapCourseAdministration::OWNER) == ilSoapCourseAdministration::OWNER && $ilObjDataCache->lookupOwner($ilObjDataCache->lookupObjId($ref_id)) == $user_id)
550  {
551  $ref_ids [] = $ref_id;
552  }
553  }
554  }
555  }
557  {
558  $owned_objects = ilObjectFactory::getObjectsForOwner("crs", $user_id);
559  foreach ($owned_objects as $obj_id) {
560  $allrefs = ilObject::_getAllReferences($obj_id);
561  foreach($allrefs as $r)
562  {
563  if($tree->isDeleted($r))
564  {
565  continue;
566  }
567  if ($tree->isInTree($r))
568  {
569  $refs[] = $r;
570  }
571  }
572  if (count($refs) > 0)
573  $ref_ids[] = array_pop($refs);
574 
575  }
576  }
577  $ref_ids = array_unique($ref_ids);
578 
579 
580 
581  $ref_ids = array_unique($ref_ids);
582 #print_r($ref_ids);
583  include_once 'webservice/soap/classes/class.ilXMLResultSetWriter.php';
584  include_once 'Modules/Course/classes/class.ilObjCourse.php';
585  include_once 'Modules/Course/classes/class.ilCourseXMLWriter.php';
586 
587  $xmlResultSet = new ilXMLResultSet();
588  $xmlResultSet->addColumn("ref_id");
589  $xmlResultSet->addColumn("xml");
590  $xmlResultSet->addColumn("parent_ref_id");
591 
592  foreach ($ref_ids as $course_id) {
593  $course_obj = $this->checkObjectAccess($course_id,"crs","write", true);
594  if ($course_obj instanceof ilObjCourse) {
595  $row = new ilXMLResultSetRow();
596  $row->setValue("ref_id", $course_id);
597  $xmlWriter = new ilCourseXMLWriter($course_obj);
598  $xmlWriter->setAttachUsers(false);
599  $xmlWriter->start();
600  $row->setValue("xml", $xmlWriter->getXML());
601  $row->setValue("parent_ref_id", $tree->getParentId($course_id));
602  $xmlResultSet->addRow($row);
603  }
604  }
605  $xmlResultSetWriter = new ilXMLResultSetWriter($xmlResultSet);
606  $xmlResultSetWriter->start();
607  return $xmlResultSetWriter->getXML();
608  }
609 }
610 ?>