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
00037 class ilConditionHandlerInterface
00038 {
00039 var $ctrl = null;
00040
00041 var $lng;
00042 var $tpl;
00043 var $tree;
00044
00045 var $ch_obj;
00046 var $target_obj;
00047 var $client_obj;
00048 var $target_id;
00049 var $target_type;
00050 var $target_title;
00051 var $target_ref_id;
00052
00053 var $automatic_validation = true;
00054
00055 function ilConditionHandlerInterface(&$gui_obj,$a_ref_id = null)
00056 {
00057 global $lng,$tpl,$tree,$ilCtrl;
00058
00059 include_once "./classes/class.ilConditionHandler.php";
00060
00061 $this->ch_obj =& new ilConditionHandler();
00062
00063 $this->ctrl =& $ilCtrl;
00064 $this->gui_obj =& $gui_obj;
00065 $this->lng =& $lng;
00066 $this->tpl =& $tpl;
00067 $this->tree =& $tree;
00068
00069 if($a_ref_id)
00070 {
00071 $this->target_obj =& ilObjectFactory::getInstanceByRefId($a_ref_id);
00072 }
00073 else
00074 {
00075 $this->target_obj =& $this->gui_obj->object;
00076 }
00077
00078
00079
00080 if (is_object($this->target_obj))
00081 {
00082 $this->setTargetId($this->target_obj->getId());
00083 $this->setTargetRefId($this->target_obj->getRefId());
00084 $this->setTargetType($this->target_obj->getType());
00085 $this->setTargetTitle($this->target_obj->getTitle());
00086 }
00087
00088 }
00089
00090 function setBackButtons($a_btn_arr)
00091 {
00092 $_SESSION['precon_btn'] = $a_btn_arr;
00093 }
00094 function getBackButtons()
00095 {
00096 return $_SESSION['precon_btn'] ? $_SESSION['precon_btn'] : array();
00097 }
00098
00099 function &executeCommand()
00100 {
00101 $next_class = $this->ctrl->getNextClass($this);
00102 $cmd = $this->ctrl->getCmd();
00103 switch ($next_class)
00104 {
00105 default:
00106 if (empty($cmd))
00107 {
00108 $cmd = "view";
00109 }
00110 $this->$cmd();
00111 break;
00112 }
00113 }
00114
00115 function setAutomaticValidation($a_status)
00116 {
00117 $this->automatic_validation = $a_status;
00118 }
00119 function getAutomaticValidation()
00120 {
00121 return $this->automatic_validation;
00122 }
00123
00124
00128 function setTargetId($a_target_id)
00129 {
00130 $this->target_id = $a_target_id;
00131 }
00132
00136 function getTargetId()
00137 {
00138 return $this->target_id;
00139 }
00140
00144 function setTargetRefId($a_target_ref_id)
00145 {
00146 $this->target_ref_id = $a_target_ref_id;
00147 }
00148
00152 function getTargetRefId()
00153 {
00154 return $this->target_ref_id;
00155 }
00156
00160 function setTargetType($a_target_type)
00161 {
00162 $this->target_type = $a_target_type;
00163 }
00164
00168 function getTargetType()
00169 {
00170 return $this->target_type;
00171 }
00172
00176 function setTargetTitle($a_target_title)
00177 {
00178 $this->target_title = $a_target_title;
00179 }
00180
00184 function getTargetTitle()
00185 {
00186 return $this->target_title;
00187 }
00188
00189 function chi_init(&$chi_target_obj,$a_ref_id = null)
00190 {
00191 echo 'deprecated';
00192
00193 include_once "./classes/class.ilConditionHandler.php";
00194
00195 $this->ch_obj =& new ilConditionHandler();
00196
00197 if($a_ref_id)
00198 {
00199 $this->target_obj =& ilObjectFactory::getInstanceByRefId($a_ref_id);
00200 }
00201 else
00202 {
00203 $this->target_obj =& $this->object;
00204 }
00205
00206 return true;
00207 }
00208
00212 function listConditions()
00213 {
00214 global $rbacsystem;
00215
00216 $this->lng->loadLanguageModule('crs');
00217
00218 $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.condition_handler_edit.html');
00219
00220 $this->__showButtons();
00221
00222 $tpl =& new ilTemplate("tpl.table.html", true, true);
00223
00224
00225 $tpl->setCurrentBlock("tbl_form_header");
00226 $tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
00227
00228 $tpl->setVariable("WIDTH",'width="60%"');
00229 $tpl->parseCurrentBlock();
00230
00231 $tpl->setCurrentBlock("tbl_action_row");
00232 $tpl->setVariable("COLUMN_COUNTS",4);
00233 $tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.gif"));
00234
00235 if(count($conditions = $this->__getConditionsOfTarget()))
00236 {
00237
00238 $tpl->setCurrentBlock("tbl_action_btn");
00239 $tpl->setVariable("BTN_NAME","delete");
00240 $tpl->setVariable("BTN_VALUE",$this->lng->txt("delete"));
00241 $tpl->parseCurrentBlock();
00242
00243 }
00244
00245 $tpl->setCurrentBlock("plain_button");
00246 $tpl->setVariable("PBTN_NAME","selector");
00247 $tpl->setVariable("PBTN_VALUE",$this->lng->txt("add_condition"));
00248 $tpl->parseCurrentBlock();
00249
00250 $tpl->setCurrentBlock("tbl_action_row");
00251 $tpl->setVariable("TPLPATH",$this->tpl->tplPath);
00252 $tpl->parseCurrentBlock();
00253
00254 $tpl->setCurrentBlock("tbl_action_row");
00255
00256 $tpl->addBlockfile("TBL_CONTENT", "tbl_content", "tpl.condition_handler_row.html");
00257
00258 $counter = 0;
00259 #foreach(ilConditionHandler::_getConditionsOfTarget($this->getTargetId(), $this->getTargetType()) as $condition)
00260 foreach($conditions as $condition)
00261 {
00262 $tmp_obj =& ilObjectFactory::getInstanceByRefId($condition['trigger_ref_id']);
00263
00264 $tpl->setCurrentBlock("tbl_content");
00265 $tpl->setVariable("CHECKBOX",ilUtil::formCheckbox(0,"conditions[]",$condition['id']));
00266 $tpl->setVariable("OBJ_TITLE",$tmp_obj->getTitle());
00267 $tpl->setVariable("OBJ_DESCRIPTION",$tmp_obj->getDescription());
00268 $tpl->setVariable("ROWCOL", ilUtil::switchColor($counter++,"tblrow2","tblrow1"));
00269
00270 $tpl->setVariable("OBJ_CONDITION",$this->lng->txt('condition_'.$condition['operator']));
00271 $tpl->setVariable("OBJ_CONDITION_VALUE",$condition['value'] ? $condition['value'] : $this->lng->txt('crs_not_available'));
00272
00273 $tpl->parseCurrentBlock();
00274 }
00275
00276
00277
00278 include_once './classes/class.ilTableGUI.php';
00279
00280 $tbl =& new ilTableGUI();
00281 $tbl->setStyle('table','std');
00282
00283
00284 $tbl->setTitle($this->getTargetTitle()." ".$this->lng->txt("preconditions"),"icon_".$this->getTargetType().".gif",
00285 $this->lng->txt("preconditions"));
00286
00287 $tbl->setHeaderNames(array("",$this->lng->txt("title"),$this->lng->txt("condition"),
00288 $this->lng->txt("value")));
00289 $tbl->setHeaderVars(array("","title","condition","value"),
00290 array("ref_id" => $this->getTargetRefId(),
00291 "cmdClass" => "ilobjcoursegui",
00292 "cmdNode" => $_GET["cmdNode"],
00293 "cmd" => "cci_edit"));
00294 $tbl->setColumnWidth(array("1%","40%","30%","30%"));
00295
00296 $tbl->setLimit($_GET["limit"]);
00297 $tbl->setOffset($_GET["offset"]);
00298 $tbl->setMaxCount(10);
00299
00300
00301 $tbl->disable("footer");
00302 $tbl->disable('sort');
00303
00304
00305 $tbl->setTemplate($tpl);
00306 $tbl->render();
00307
00308 $this->tpl->setVariable("PRECONDITION_TABLE",$tpl->get());
00309
00310 return true;
00311 }
00312
00313 function delete()
00314 {
00315 if(!count($_POST['conditions']))
00316 {
00317 sendInfo('no_condition_selected');
00318
00319 return true;
00320 }
00321
00322 foreach($_POST['conditions'] as $condition_id)
00323 {
00324 $this->ch_obj->deleteCondition($condition_id);
00325 }
00326 sendInfo($this->lng->txt('condition_deleted'));
00327 $this->listConditions();
00328
00329 return true;
00330 }
00331
00332 function selector()
00333 {
00334 include_once ("classes/class.ilConditionSelector.php");
00335
00336 $this->tpl->addBlockFile('ADM_CONTENT', "adm_content", "tpl.condition_selector.html");
00337
00338 $this->__showButtons();
00339
00340 sendInfo($this->lng->txt("condition_select_object"));
00341
00342 $exp = new ilConditionSelector($this->ctrl->getLinkTarget($this,'copySelector'));
00343 $exp->setExpand($_GET["condition_selector_expand"] ? $_GET["condition_selector_expand"] : $this->tree->readRootId());
00344 $exp->setExpandTarget($this->ctrl->getLinkTarget($this,'selector'));
00345 $exp->setTargetGet("ref_id");
00346 $exp->setRefId($this->getTargetRefId());
00347
00348 $exp->addFilter('crs');
00349 $exp->addFilter('tst');
00350
00351 $exp->setSelectableTypes($this->ch_obj->getTriggerTypes());
00352 $exp->setControlClass($this);
00353
00354 $exp->setOutput(0);
00355
00356 $this->tpl->setCurrentBlock("adm_content");
00357 $this->tpl->setVariable("EXPLORER",$exp->getOutput());
00358 $this->tpl->parseCurrentBlock();
00359 }
00360
00361 function add()
00362 {
00363
00364 $tmp_source_obj =& ilObjectFactory::getInstanceByRefId((int) $_GET['source_id']);
00365
00366 include_once "./classes/class.ilConditionHandler.php";
00367
00368 $ch_obj =& new ilConditionHandler();
00369
00370 $operators[] = $this->lng->txt('condition_select_one');
00371 foreach($ch_obj->getOperatorsByTargetType($tmp_source_obj->getType()) as $operator)
00372 {
00373 $operators[$operator] = $this->lng->txt('condition_'.$operator);
00374 }
00375
00376 $this->tpl->addBlockFile('ADM_CONTENT','adm_content','tpl.condition_handler_add.html');
00377
00378 $this->__showButtons();
00379
00380
00381 #this->tpl->setCurrentBlock("btn_cell");
00382 #this->tpl->setVariable("BTN_LINK",$this->ctrl->getLinkTarget($this,'selector'));
00383 #this->tpl->setVariable("BTN_TXT",$this->lng->txt('new_selection'));
00384 #this->tpl->parseCurrentBlock();
00385
00386 $this->ctrl->setParameter($this,'source_id',(int) $_GET['source_id']);
00387 $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
00388 $this->tpl->setVariable("CSS_TABLE",'std');
00389 $this->tpl->setVariable("WIDTH",'50%');
00390 $this->tpl->setVariable("TBL_TITLE_IMG",ilUtil::getImagePath('icon_'.$this->getTargetType().'.gif'));
00391 $this->tpl->setVariable("TBL_TITLE_ALT",$this->lng->txt('obj_',$this->getTargetType()));
00392
00393
00394 $this->tpl->setVariable("CONDITION_SELECT",ilUtil::formSelect('',
00395 "operator",
00396 $operators,
00397 false,
00398 true));
00399
00400 $title = $this->lng->txt('add_condition').' ('.$tmp_source_obj->getTitle().')';
00401 unset($tmp_source_obj);
00402
00403 $this->tpl->setVariable("TBL_TITLE",$title);
00404
00405 $this->tpl->setVariable("TXT_ADD",$this->lng->txt('add_condition'));
00406 $this->tpl->setVariable("CMD_ADD",'assign');
00407
00408 return true;
00409 }
00410
00411
00415 function assign()
00416 {
00417 if(!isset($_GET['source_id']))
00418 {
00419 echo "class.ilConditionHandlerInterface: no source_id given";
00420
00421 return false;
00422 }
00423 if(!strlen($_POST['operator']))
00424 {
00425 sendInfo($this->lng->txt('no_operator_selected'));
00426 $this->add();
00427
00428 return false;
00429 }
00430
00431
00432 $this->ch_obj->setTargetRefId($this->getTargetRefId());
00433 $this->ch_obj->setTargetObjId($this->getTargetId());
00434 $this->ch_obj->setTargetType($this->getTargetType());
00435
00436
00437 if(!$trigger_obj =& ilObjectFactory::getInstanceByRefId((int) $_GET['source_id'],false))
00438 {
00439 echo 'ilConditionHandler: Trigger object does not exist';
00440 }
00441 $this->ch_obj->setTriggerRefId($trigger_obj->getRefId());
00442 $this->ch_obj->setTriggerObjId($trigger_obj->getId());
00443 $this->ch_obj->setTriggerType($trigger_obj->getType());
00444 $this->ch_obj->setOperator($_POST['operator']);
00445 $this->ch_obj->setValue('');
00446
00447 $this->ch_obj->enableAutomaticValidation($this->getAutomaticValidation());
00448 if(!$this->ch_obj->storeCondition())
00449 {
00450 sendInfo($this->ch_obj->getErrorMessage());
00451 }
00452 else
00453 {
00454 sendInfo($this->lng->txt('added_new_condition'));
00455 }
00456
00457 $this->listConditions();
00458
00459 return true;
00460 }
00461
00462 function chi_update()
00463 {
00464 #if(in_array('',$_POST['operator']))
00465 #{
00466 # sendInfo($this->lng->txt('select_one_operator'));
00467
00468 # return false;
00469 #}
00470 foreach($this->__getConditionsOfTarget() as $condition)
00471 {
00472 $this->ch_obj->setOperator($_POST['operator'][$condition["id"]]);
00473 $this->ch_obj->setValue($_POST['value'][$condition["id"]]);
00474 $this->ch_obj->updateCondition($condition['id']);
00475
00476 }
00477 sendInfo($this->lng->txt('conditions_updated'));
00478
00479 $this->ctrl->returnToParent($this);
00480
00481 return true;
00482 }
00483 function __getConditionsOfTarget()
00484 {
00485 include_once './classes/class.ilConditionHandler.php';
00486
00487 foreach(ilConditionHandler::_getConditionsOfTarget($this->getTargetId(), $this->getTargetType()) as $condition)
00488 {
00489 if($condition['operator'] == 'not_member')
00490 {
00491 continue;
00492 }
00493 else
00494 {
00495 $cond[] = $condition;
00496 }
00497 }
00498 return $cond ? $cond : array();
00499 }
00500
00501 function __showButtons()
00502 {
00503 if(!$this->getBackButtons())
00504 {
00505 return false;
00506 }
00507
00508 $this->tpl->addBlockfile("BUTTONS", "buttons", "tpl.buttons.html");
00509 foreach($this->getBackButtons() as $name => $link)
00510 {
00511 $this->tpl->setCurrentBlock("btn_cell");
00512 $this->tpl->setVariable("BTN_LINK",$link);
00513 $this->tpl->setVariable("BTN_TXT",$this->lng->txt($name));
00514 $this->tpl->parseCurrentBlock();
00515 }
00516 }
00517
00518 }
00519 ?>