ILIAS  Release_3_10_x_branch Revision 61812
 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  if(!$this->__checkSession($sid))
52  {
53  return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
54  }
55 
56  if(!is_numeric($target_id))
57  {
58  return $this->__raiseError('No valid target id given. Please choose an existing reference id of an ILIAS category',
59  'Client');
60  }
61 
62  // Include main header
63  include_once './include/inc.header.php';
64  global $rbacsystem;
65 
66  if(!$target_obj =& ilObjectFactory::getInstanceByRefId($target_id, false))
67  {
68  return $this->__raiseError('No valid target given.', 'Client');
69  }
70 
72  {
73  return $this->__raiseError("Parent with ID $target_id has been deleted.", 'CLIENT_OBJECT_DELETED');
74  }
75 
76  if(!$rbacsystem->checkAccess('create',$target_id,'crs'))
77  {
78  return $this->__raiseError('Check access failed. No permission to create courses','Server');
79  }
80 
81  // Start import
82  include_once("Modules/Course/classes/class.ilObjCourse.php");
83 
84  $newObj = new ilObjCourse();
85  $newObj->setType('crs');
86  $newObj->setTitle('dummy');
87  $newObj->setDescription("");
88  $newObj->create(true); // true for upload
89  $newObj->createReference();
90  $newObj->putInTree($target_id);
91  $newObj->setPermissions($target_id);
92  $newObj->initDefaultRoles();
93 
94  include_once 'Modules/Course/classes/class.ilCourseXMLParser.php';
95 
96  $xml_parser = new ilCourseXMLParser($newObj);
97  $xml_parser->setXMLContent($crs_xml);
98 
99  $xml_parser->startParsing();
100 
101  $newObj->MDUpdateListener('General');
102 
103  return $newObj->getRefId() ? $newObj->getRefId() : "0";
104 
105  }
106 
107  function deleteCourse($sid,$course_id)
108  {
109  if(!$this->__checkSession($sid))
110  {
111  return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
112  }
113 
114  if(!is_numeric($course_id))
115  {
116  return $this->__raiseError('No valid course id given. Please choose an existing reference id of an ILIAS course',
117  'Client');
118  }
119 
120  // Include main header
121  include_once './include/inc.header.php';
122  include_once "./Services/Utilities/classes/class.ilUtil.php";
123  global $rbacsystem;
124 
125  if(($obj_type = ilObject::_lookupType(ilObject::_lookupObjId($course_id))) != 'crs')
126  {
127  $course_id = end($ref_ids = ilObject::_getAllReferences($course_id));
128  if(ilObject::_lookupType(ilObject::_lookupObjId($course_id)) != 'crs')
129  {
130  return $this->__raiseError('Invalid course id. Object with id "'. $course_id.'" is not of type "course"','Client');
131  }
132  }
133 
134  if(!$rbacsystem->checkAccess('delete',$course_id))
135  {
136  return $this->__raiseError('Check access failed. No permission to delete course','Server');
137  }
138 
139 
140  global $tree,$rbacadmin,$log;
141 
142  if($tree->isDeleted($course_id))
143  {
144  return $this->__raiseError('Node already deleted','Server');
145  }
146 
147  $subnodes = $tree->getSubtree($tree->getNodeData($course_id));
148  foreach ($subnodes as $subnode)
149  {
150  $rbacadmin->revokePermission($subnode["child"]);
151 
152  // remove item from all user desktops
153  $affected_users = ilUtil::removeItemFromDesktops($subnode["child"]);
154 
155  }
156  if(!$tree->saveSubTree($course_id))
157  {
158  return $this->__raiseError('Node already deleted','Client');
159  }
160 
161  // write log entry
162  $log->write("SOAP ilObjectGUI::confirmedDeleteObject(), moved ref_id ".$course_id." to trash");
163 
164  // remove item from all user desktops
165  $affected_users = ilUtil::removeItemFromDesktops($course_id);
166 
167  return true;
168  }
169 
170  function assignCourseMember($sid,$course_id,$user_id,$type)
171  {
172  if(!$this->__checkSession($sid))
173  {
174  return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
175  }
176 
177  if(!is_numeric($course_id))
178  {
179  return $this->__raiseError('No valid course id given. Please choose an existing reference id of an ILIAS course',
180  'Client');
181  }
182 
183  // Include main header
184  include_once './include/inc.header.php';
185 
186  global $rbacsystem;
187 
188  if(($obj_type = ilObject::_lookupType(ilObject::_lookupObjId($course_id))) != 'crs')
189  {
190  $course_id = end($ref_ids = ilObject::_getAllReferences($course_id));
191  if(ilObject::_lookupType(ilObject::_lookupObjId($course_id)) != 'crs')
192  {
193  return $this->__raiseError('Invalid course id. Object with id "'. $course_id.'" is not of type "course"','Client');
194  }
195  }
196 
197  if(!$rbacsystem->checkAccess('write',$course_id))
198  {
199  return $this->__raiseError('Check access failed. No permission to write to course','Server');
200  }
201 
202 
203  if(ilObject::_lookupType($user_id) != 'usr')
204  {
205  return $this->__raiseError('Invalid user id. User with id "'. $user_id.' does not exist','Client');
206  }
207  if($type != 'Admin' and
208  $type != 'Tutor' and
209  $type != 'Member')
210  {
211  return $this->__raiseError('Invalid type given. Parameter "type" must be "Admin", "Tutor" or "Member"','Client');
212  }
213 
214  if(!$tmp_course = ilObjectFactory::getInstanceByRefId($course_id,false))
215  {
216  return $this->__raiseError('Cannot create course instance!','Server');
217  }
218 
219  if(!$tmp_user = ilObjectFactory::getInstanceByObjId($user_id,false))
220  {
221  return $this->__raiseError('Cannot create user instance!','Server');
222  }
223 
224  include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
225 
226  $course_members = ilCourseParticipants::_getInstanceByObjId($tmp_course->getId());
227 
228  switch($type)
229  {
230  case 'Admin':
231  $course_members->add($tmp_user->getId(),IL_CRS_ADMIN);
232  $course_members->updateNotification($tmp_user->getId(),1);
233  break;
234 
235  case 'Tutor':
236  $course_members->add($tmp_user->getId(),IL_CRS_TUTOR);
237  break;
238 
239  case 'Member':
240  $course_members->add($tmp_user->getId(),IL_CRS_MEMBER);
241  break;
242  }
243 
244  return true;
245  }
246 
247  function excludeCourseMember($sid,$course_id,$user_id)
248  {
249  if(!$this->__checkSession($sid))
250  {
251  return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
252  }
253  if(!is_numeric($course_id))
254  {
255  return $this->__raiseError('No valid course id given. Please choose an existing reference id of an ILIAS course',
256  'Client');
257  }
258 
259  // Include main header
260  include_once './include/inc.header.php';
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  if(!$this->__checkSession($sid))
304  {
305  return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
306  }
307  if(!is_numeric($course_id))
308  {
309  return $this->__raiseError('No valid course id given. Please choose an existing reference id of an ILIAS course',
310  'Client');
311  }
312  // Include main header
313  include_once './include/inc.header.php';
314  global $rbacsystem;
315 
316  if(($obj_type = ilObject::_lookupType(ilObject::_lookupObjId($course_id))) != 'crs')
317  {
318  $course_id = end($ref_ids = ilObject::_getAllReferences($course_id));
319  if(ilObject::_lookupType(ilObject::_lookupObjId($course_id)) != 'crs')
320  {
321  return $this->__raiseError('Invalid course id. Object with id "'. $course_id.'" is not of type "course"','Client');
322  }
323  }
324 
325  if(ilObject::_lookupType($user_id) != 'usr')
326  {
327  return $this->__raiseError('Invalid user id. User with id "'. $user_id.' does not exist','Client');
328  }
329 
330  if(!$tmp_course = ilObjectFactory::getInstanceByRefId($course_id,false))
331  {
332  return $this->__raiseError('Cannot create course instance!','Server');
333  }
334 
335  if(!$rbacsystem->checkAccess('write',$course_id))
336  {
337  return $this->__raiseError('Check access failed. No permission to write to course','Server');
338  }
339 
340  include_once './Modules/Course/classes/class.ilCourseParticipants.php';
341  $crs_members = ilCourseParticipants::_getInstanceByObjId($tmp_course->getId());
342 
343  if($crs_members->isAdmin($user_id))
344  {
345  return IL_CRS_ADMIN;
346  }
347  if($crs_members->isTutor($user_id))
348  {
349  return IL_CRS_TUTOR;
350  }
351  if($crs_members->isMember($user_id))
352  {
353  return IL_CRS_MEMBER;
354  }
355 
356  return "0";
357  }
358 
359 
360  function getCourseXML($sid,$course_id)
361  {
362  if(!$this->__checkSession($sid))
363  {
364  return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
365  }
366  if(!is_numeric($course_id))
367  {
368  return $this->__raiseError('No valid course id given. Please choose an existing reference id of an ILIAS course',
369  'Client');
370  }
371 
372  // Include main header
373  include_once './include/inc.header.php';
374 
375  global $rbacsystem;
376 
377  $tmp_course = $this->checkObjectAccess($course_id, "crs", "read", true);
378  if ($this->isFault($tmp_course)) {
379  return $tmp_course;
380  }
381 
382  /*if(($obj_type = ilObject::_lookupType(ilObject::_lookupObjId($course_id))) != 'crs')
383  {
384  $course_id = end($ref_ids = ilObject::_getAllReferences($course_id));
385  if(ilObject::_lookupType(ilObject::_lookupObjId($course_id)) != 'crs')
386  {
387  return $this->__raiseError('Invalid course id. Object with id "'. $course_id.'" is not of type "course"','Client');
388  }
389  }
390 
391  if(!$tmp_course = ilObjectFactory::getInstanceByRefId($course_id,false))
392  {
393  return $this->__raiseError('Cannot create course instance!','Server');
394  }
395 
396  if(!$rbacsystem->checkAccess('read',$course_id))
397  {
398  return $this->__raiseError('Check access failed. No permission to read course','Server');
399  }*/
400 
401  include_once 'Modules/Course/classes/class.ilCourseXMLWriter.php';
402 
403  $xml_writer = new ilCourseXMLWriter($tmp_course);
404  $xml_writer->start();
405 
406  return $xml_writer->getXML();
407  }
408 
409  function updateCourse($sid,$course_id,$xml)
410  {
411  if(!$this->__checkSession($sid))
412  {
413  return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
414  }
415 
416  if(!is_numeric($course_id))
417  {
418  return $this->__raiseError('No valid course id given. Please choose an existing reference id of an ILIAS course',
419  'Client');
420  }
421 
422  // Include main header
423  include_once './include/inc.header.php';
424 
425  global $rbacsystem;
426 
427  if(($obj_type = ilObject::_lookupType(ilObject::_lookupObjId($course_id))) != 'crs')
428  {
429  $course_id = end($ref_ids = ilObject::_getAllReferences($course_id));
430  if(ilObject::_lookupType(ilObject::_lookupObjId($course_id)) != 'crs')
431  {
432  return $this->__raiseError('Invalid course id. Object with id "'. $course_id.'" is not of type "course"','Client');
433  }
434  }
435 
436  if(!$tmp_course = ilObjectFactory::getInstanceByRefId($course_id,false))
437  {
438  return $this->__raiseError('Cannot create course instance!','Server');
439  }
440 
441  if(!$rbacsystem->checkAccess('write',$course_id))
442  {
443  return $this->__raiseError('Check access failed. No permission to write course','Server');
444  }
445 
446 
447  // First delete old meta data
448  include_once 'Services/MetaData/classes/class.ilMD.php';
449 
450  $md = new ilMD($tmp_course->getId(),0,'crs');
451  $md->deleteAll();
452 
453  include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
454  ilCourseParticipants::_deleteAllEntries($tmp_course->getId());
455 
456 
457  include_once 'Modules/Course/classes/class.ilCourseWaitingList.php';
458  ilCourseWaitingList::_deleteAll($tmp_course->getId());
459 
460  include_once 'Modules/Course/classes/class.ilCourseXMLParser.php';
461 
462  $xml_parser = new ilCourseXMLParser($tmp_course);
463  $xml_parser->setXMLContent($xml);
464 
465  $xml_parser->startParsing();
466 
467  $tmp_course->MDUpdateListener('General');
468 
469  return true;
470  }
471 
472  // PRIVATE
473 
481  function getCoursesForUser($sid, $parameters) {
482 
483  if(!$this->__checkSession($sid))
484  {
485  return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
486  }
487  // Include main header
488  include_once './include/inc.header.php';
489  global $rbacreview, $ilObjDataCache, $tree;
490 
491  include_once 'webservice/soap/classes/class.ilXMLResultSetParser.php';
492  $parser = new ilXMLResultSetParser($parameters);
493  try {
494  $parser->startParsing();
495  } catch (ilSaxParserException $exception) {
496  return $this->__raiseError($exception->getMessage(), "Client");
497  }
498  $xmlResultSet = $parser->getXMLResultSet();
499 
500  if (!$xmlResultSet->hasColumn ("user_id"))
501  return $this->__raiseError("parameter user_id is missing", "Client");
502 
503  if (!$xmlResultSet->hasColumn ("status"))
504  return $this->__raiseError("parameter status is missing", "Client");
505 
506  $user_id = (int) $xmlResultSet->getValue (0, "user_id");
507  $status = (int) $xmlResultSet->getValue (0, "status");
508 
509  $ref_ids = array();
510 
511  // get roles
512 #var_dump($xmlResultSet);
513 #echo "uid:".$user_id;
514 #echo "status:".$status;
518  foreach($rbacreview->assignedRoles($user_id) as $role_id)
519  {
520  if($role = ilObjectFactory::getInstanceByObjId($role_id,false))
521  {
522  #echo $role->getType();
523  if ($role->getType() != "role")
524  continue;
525  if ($role->getParent() == ROLE_FOLDER_ID)
526  {
527  continue;
528  }
529  $role_title = $role->getTitle();
530 
531  if ($ref_id = ilUtil::__extractRefId($role_title))
532  {
534  continue;
535 
536  #echo $role_title;
537  if (ilSoapCourseAdministration::MEMBER == ($status & ilSoapCourseAdministration::MEMBER) && strpos($role_title, "member") !== false)
538  {
539  $ref_ids [] = $ref_id;
540  } elseif (ilSoapCourseAdministration::TUTOR == ($status & ilSoapCourseAdministration::TUTOR) && strpos($role_title, "tutor") !== false)
541  {
542  $ref_ids [] = $ref_id;
543  } elseif (ilSoapCourseAdministration::ADMIN == ($status & ilSoapCourseAdministration::ADMIN) && strpos($role_title, "admin") !== false)
544  {
545  $ref_ids [] = $ref_id;
546  } elseif (($status & ilSoapCourseAdministration::OWNER) == ilSoapCourseAdministration::OWNER && $ilObjDataCache->lookupOwner($ilObjDataCache->lookupObjId($ref_id)) == $user_id)
547  {
548  $ref_ids [] = $ref_id;
549  }
550  }
551  }
552  }
554  {
555  $owned_objects = ilObjectFactory::getObjectsForOwner("crs", $user_id);
556  foreach ($owned_objects as $obj_id) {
557  $allrefs = ilObject::_getAllReferences($obj_id);
558  foreach($allrefs as $r)
559  {
560  if ($tree->isInTree($r))
561  {
562  $refs[] = $r;
563  }
564  }
565  if (count($refs) > 0)
566  $ref_ids[] = array_pop($refs);
567 
568  }
569  }
570  $ref_ids = array_unique($ref_ids);
571 
572 
573 
574  $ref_ids = array_unique($ref_ids);
575 #print_r($ref_ids);
576  include_once 'webservice/soap/classes/class.ilXMLResultSetWriter.php';
577  include_once 'Modules/Course/classes/class.ilObjCourse.php';
578  include_once 'Modules/Course/classes/class.ilCourseXMLWriter.php';
579 
580  $xmlResultSet = new ilXMLResultSet();
581  $xmlResultSet->addColumn("ref_id");
582  $xmlResultSet->addColumn("xml");
583  $xmlResultSet->addColumn("parent_ref_id");
584 
585  foreach ($ref_ids as $course_id) {
586  $course_obj = $this->checkObjectAccess($course_id,"crs","write", true);
587  if ($course_obj instanceof ilObjCourse) {
588  $row = new ilXMLResultSetRow();
589  $row->setValue("ref_id", $course_id);
590  $xmlWriter = new ilCourseXMLWriter($course_obj);
591  $xmlWriter->setAttachUsers(false);
592  $xmlWriter->start();
593  $row->setValue("xml", $xmlWriter->getXML());
594  $row->setValue("parent_ref_id", $tree->getParentId($course_id));
595  $xmlResultSet->addRow($row);
596  }
597  }
598  $xmlResultSetWriter = new ilXMLResultSetWriter($xmlResultSet);
599  $xmlResultSetWriter->start();
600  return $xmlResultSetWriter->getXML();
601  }
602 }
603 ?>