ILIAS  Release_4_1_x_branch Revision 61804
 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 
95  include_once 'Modules/Course/classes/class.ilCourseXMLParser.php';
96 
97  $xml_parser = new ilCourseXMLParser($newObj);
98  $xml_parser->setXMLContent($crs_xml);
99  $xml_parser->startParsing();
100  return $newObj->getRefId() ? $newObj->getRefId() : "0";
101 
102  }
103 
104  function deleteCourse($sid,$course_id)
105  {
106  $this->initAuth($sid);
107  $this->initIlias();
108 
109  if(!$this->__checkSession($sid))
110  {
111  return $this->__raiseError($this->__getMessage(),$this->__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_once "./Services/Utilities/classes/class.ilUtil.php";
121  global $rbacsystem;
122 
123  if(($obj_type = ilObject::_lookupType(ilObject::_lookupObjId($course_id))) != 'crs')
124  {
125  $course_id = end($ref_ids = ilObject::_getAllReferences($course_id));
126  if(ilObject::_lookupType(ilObject::_lookupObjId($course_id)) != 'crs')
127  {
128  return $this->__raiseError('Invalid course id. Object with id "'. $course_id.'" is not of type "course"','Client');
129  }
130  }
131 
132  if(!$rbacsystem->checkAccess('delete',$course_id))
133  {
134  return $this->__raiseError('Check access failed. No permission to delete course','Server');
135  }
136 
137 
138  global $tree,$rbacadmin,$log;
139 
140  if($tree->isDeleted($course_id))
141  {
142  return $this->__raiseError('Node already deleted','Server');
143  }
144 
145  $subnodes = $tree->getSubtree($tree->getNodeData($course_id));
146  foreach ($subnodes as $subnode)
147  {
148  $rbacadmin->revokePermission($subnode["child"]);
149 
150  // remove item from all user desktops
151  $affected_users = ilUtil::removeItemFromDesktops($subnode["child"]);
152 
153  }
154  if(!$tree->saveSubTree($course_id))
155  {
156  return $this->__raiseError('Node already deleted','Client');
157  }
158 
159  // write log entry
160  $log->write("SOAP ilObjectGUI::confirmedDeleteObject(), moved ref_id ".$course_id." to trash");
161 
162  // remove item from all user desktops
163  $affected_users = ilUtil::removeItemFromDesktops($course_id);
164 
165  return true;
166  }
167 
168  function assignCourseMember($sid,$course_id,$user_id,$type)
169  {
170  $this->initAuth($sid);
171  $this->initIlias();
172 
173  if(!$this->__checkSession($sid))
174  {
175  return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
176  }
177 
178  if(!is_numeric($course_id))
179  {
180  return $this->__raiseError('No valid course id given. Please choose an existing reference id of an ILIAS course',
181  'Client');
182  }
183 
184  global $rbacsystem;
185 
186  if(($obj_type = ilObject::_lookupType(ilObject::_lookupObjId($course_id))) != 'crs')
187  {
188  $course_id = end($ref_ids = ilObject::_getAllReferences($course_id));
189  if(ilObject::_lookupType(ilObject::_lookupObjId($course_id)) != 'crs')
190  {
191  return $this->__raiseError('Invalid course id. Object with id "'. $course_id.'" is not of type "course"','Client');
192  }
193  }
194 
195  if(!$rbacsystem->checkAccess('write',$course_id))
196  {
197  return $this->__raiseError('Check access failed. No permission to write to course','Server');
198  }
199 
200 
201  if(ilObject::_lookupType($user_id) != 'usr')
202  {
203  return $this->__raiseError('Invalid user id. User with id "'. $user_id.' does not exist','Client');
204  }
205  if($type != 'Admin' and
206  $type != 'Tutor' and
207  $type != 'Member')
208  {
209  return $this->__raiseError('Invalid type given. Parameter "type" must be "Admin", "Tutor" or "Member"','Client');
210  }
211 
212  if(!$tmp_course = ilObjectFactory::getInstanceByRefId($course_id,false))
213  {
214  return $this->__raiseError('Cannot create course instance!','Server');
215  }
216 
217  if(!$tmp_user = ilObjectFactory::getInstanceByObjId($user_id,false))
218  {
219  return $this->__raiseError('Cannot create user instance!','Server');
220  }
221 
222  include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
223 
224  $course_members = ilCourseParticipants::_getInstanceByObjId($tmp_course->getId());
225 
226  switch($type)
227  {
228  case 'Admin':
229  $course_members->add($tmp_user->getId(),IL_CRS_ADMIN);
230  $course_members->updateNotification($tmp_user->getId(),1);
231  break;
232 
233  case 'Tutor':
234  $course_members->add($tmp_user->getId(),IL_CRS_TUTOR);
235  break;
236 
237  case 'Member':
238  $course_members->add($tmp_user->getId(),IL_CRS_MEMBER);
239  break;
240  }
241 
242  return true;
243  }
244 
245  function excludeCourseMember($sid,$course_id,$user_id)
246  {
247  $this->initAuth($sid);
248  $this->initIlias();
249 
250  if(!$this->__checkSession($sid))
251  {
252  return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
253  }
254  if(!is_numeric($course_id))
255  {
256  return $this->__raiseError('No valid course id given. Please choose an existing reference id of an ILIAS course',
257  'Client');
258  }
259 
260  global $rbacsystem;
261 
262  if(($obj_type = ilObject::_lookupType(ilObject::_lookupObjId($course_id))) != 'crs')
263  {
264  $course_id = end($ref_ids = ilObject::_getAllReferences($course_id));
265  if(ilObject::_lookupType(ilObject::_lookupObjId($course_id)) != 'crs')
266  {
267  return $this->__raiseError('Invalid course id. Object with id "'. $course_id.'" is not of type "course"','Client');
268  }
269  }
270 
271  if(ilObject::_lookupType($user_id) != 'usr')
272  {
273  return $this->__raiseError('Invalid user id. User with id "'. $user_id.' does not exist','Client');
274  }
275 
276  if(!$tmp_course = ilObjectFactory::getInstanceByRefId($course_id,false))
277  {
278  return $this->__raiseError('Cannot create course instance!','Server');
279  }
280 
281  if(!$rbacsystem->checkAccess('write',$course_id))
282  {
283  return $this->__raiseError('Check access failed. No permission to write to course','Server');
284  }
285 
286  include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
287 
288  $course_members = ilCourseParticipants::_getInstanceByObjId($tmp_course->getId());
289  if(!$course_members->checkLastAdmin(array($user_id)))
290  {
291  return $this->__raiseError('Cannot deassign last administrator from course','Server');
292  }
293 
294  $course_members->delete($user_id);
295 
296  return true;
297  }
298 
299 
300  function isAssignedToCourse($sid,$course_id,$user_id)
301  {
302  $this->initAuth($sid);
303  $this->initIlias();
304 
305  if(!$this->__checkSession($sid))
306  {
307  return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
308  }
309  if(!is_numeric($course_id))
310  {
311  return $this->__raiseError('No valid course id given. Please choose an existing reference id of an ILIAS course',
312  'Client');
313  }
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  $this->initAuth($sid);
363  $this->initIlias();
364 
365  if(!$this->__checkSession($sid))
366  {
367  return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
368  }
369  if(!is_numeric($course_id))
370  {
371  return $this->__raiseError('No valid course id given. Please choose an existing reference id of an ILIAS course',
372  'Client');
373  }
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  $this->initAuth($sid);
412  $this->initIlias();
413 
414  if(!$this->__checkSession($sid))
415  {
416  return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
417  }
418 
419  if(!is_numeric($course_id))
420  {
421  return $this->__raiseError('No valid course id given. Please choose an existing reference id of an ILIAS course',
422  'Client');
423  }
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  $this->initAuth($sid);
484  $this->initIlias();
485 
486  if(!$this->__checkSession($sid))
487  {
488  return $this->__raiseError($this->__getMessage(),$this->__getMessageCode());
489  }
490 
491  global $rbacreview, $ilObjDataCache, $tree;
492 
493  include_once 'webservice/soap/classes/class.ilXMLResultSetParser.php';
494  $parser = new ilXMLResultSetParser($parameters);
495  try {
496  $parser->startParsing();
497  } catch (ilSaxParserException $exception) {
498  return $this->__raiseError($exception->getMessage(), "Client");
499  }
500  $xmlResultSet = $parser->getXMLResultSet();
501 
502  if (!$xmlResultSet->hasColumn ("user_id"))
503  return $this->__raiseError("parameter user_id is missing", "Client");
504 
505  if (!$xmlResultSet->hasColumn ("status"))
506  return $this->__raiseError("parameter status is missing", "Client");
507 
508  $user_id = (int) $xmlResultSet->getValue (0, "user_id");
509  $status = (int) $xmlResultSet->getValue (0, "status");
510 
511  $ref_ids = array();
512 
513  // get roles
514 #var_dump($xmlResultSet);
515 #echo "uid:".$user_id;
516 #echo "status:".$status;
520  foreach($rbacreview->assignedRoles($user_id) as $role_id)
521  {
522  if($role = ilObjectFactory::getInstanceByObjId($role_id,false))
523  {
524  #echo $role->getType();
525  if ($role->getType() != "role")
526  continue;
527  if ($role->getParent() == ROLE_FOLDER_ID)
528  {
529  continue;
530  }
531  $role_title = $role->getTitle();
532 
533  if ($ref_id = ilUtil::__extractRefId($role_title))
534  {
536  continue;
537 
538  #echo $role_title;
539  if (ilSoapCourseAdministration::MEMBER == ($status & ilSoapCourseAdministration::MEMBER) && strpos($role_title, "member") !== false)
540  {
541  $ref_ids [] = $ref_id;
542  } elseif (ilSoapCourseAdministration::TUTOR == ($status & ilSoapCourseAdministration::TUTOR) && strpos($role_title, "tutor") !== false)
543  {
544  $ref_ids [] = $ref_id;
545  } elseif (ilSoapCourseAdministration::ADMIN == ($status & ilSoapCourseAdministration::ADMIN) && strpos($role_title, "admin") !== false)
546  {
547  $ref_ids [] = $ref_id;
548  } elseif (($status & ilSoapCourseAdministration::OWNER) == ilSoapCourseAdministration::OWNER && $ilObjDataCache->lookupOwner($ilObjDataCache->lookupObjId($ref_id)) == $user_id)
549  {
550  $ref_ids [] = $ref_id;
551  }
552  }
553  }
554  }
556  {
557  $owned_objects = ilObjectFactory::getObjectsForOwner("crs", $user_id);
558  foreach ($owned_objects as $obj_id) {
559  $allrefs = ilObject::_getAllReferences($obj_id);
560  foreach($allrefs as $r)
561  {
562  if($tree->isDeleted($r))
563  {
564  continue;
565  }
566  if ($tree->isInTree($r))
567  {
568  $refs[] = $r;
569  }
570  }
571  if (count($refs) > 0)
572  $ref_ids[] = array_pop($refs);
573 
574  }
575  }
576  $ref_ids = array_unique($ref_ids);
577 
578 
579 
580  $ref_ids = array_unique($ref_ids);
581 #print_r($ref_ids);
582  include_once 'webservice/soap/classes/class.ilXMLResultSetWriter.php';
583  include_once 'Modules/Course/classes/class.ilObjCourse.php';
584  include_once 'Modules/Course/classes/class.ilCourseXMLWriter.php';
585 
586  $xmlResultSet = new ilXMLResultSet();
587  $xmlResultSet->addColumn("ref_id");
588  $xmlResultSet->addColumn("xml");
589  $xmlResultSet->addColumn("parent_ref_id");
590 
591  foreach ($ref_ids as $course_id) {
592  $course_obj = $this->checkObjectAccess($course_id,"crs","write", true);
593  if ($course_obj instanceof ilObjCourse) {
594  $row = new ilXMLResultSetRow();
595  $row->setValue("ref_id", $course_id);
596  $xmlWriter = new ilCourseXMLWriter($course_obj);
597  $xmlWriter->setAttachUsers(false);
598  $xmlWriter->start();
599  $row->setValue("xml", $xmlWriter->getXML());
600  $row->setValue("parent_ref_id", $tree->getParentId($course_id));
601  $xmlResultSet->addRow($row);
602  }
603  }
604  $xmlResultSetWriter = new ilXMLResultSetWriter($xmlResultSet);
605  $xmlResultSetWriter->start();
606  return $xmlResultSetWriter->getXML();
607  }
608 }
609 ?>