ILIAS PHP Cross Reference Learning Management Systems

Source: /Modules/TestQuestionPool/classes/class.ilMatchingWizardInputGUI.php - 412 lines - 11296 bytes - Summary - Text - Print

   1  <?php
   2  /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
   3  
   4  require_once  './Modules/TestQuestionPool/classes/class.ilSingleChoiceWizardInputGUI.php';
   5  
   6  /**
   7   * This class represents a single choice wizard property in a property form.
   8   *
   9   * @author Helmut Schottmüller <ilias@aurealis.de> 
  10   * @author Maximilian Becker <mbecker@databay.de> 
  11   * 
  12   * @version $Id: class.ilMatchingWizardInputGUI.php 44048 2013-08-09 14:58:01Z mbecker $
  13   *
  14   * @ingroup ModulesTestQuestionPool
  15   */
  16  class ilMatchingWizardInputGUI extends ilTextInputGUI
  17  {
  18      protected $text_name = '';
  19      protected $image_name = '';
  20      protected $values = array();
  21      protected $allowMove = false;
  22      protected $qstObject = null;
  23      protected $suffixes = array();
  24      protected $hideImages = false;
  25  
  26      /**
  27       * Constructor
  28       *
  29       * @param    string    $a_title    Title
  30       * @param    string    $a_postvar    Post Variable
  31       * 
  32       * @return \ilMatchingWizardInputGUI
  33       */
  34  	function __construct($a_title = "", $a_postvar = "")
  35      {
  36          global $lng;
  37          
  38          parent::__construct($a_title, $a_postvar);
  39          $this->setSuffixes(array("jpg", "jpeg", "png", "gif"));
  40          $this->setSize('50');
  41          $this->text_name = $lng->txt('answer_text');
  42          $this->image_name = $lng->txt('answer_image');
  43      }
  44      
  45      /**
  46      * Set Accepted Suffixes.
  47      *
  48      * @param    array    $a_suffixes    Accepted Suffixes
  49      */
  50  	function setSuffixes($a_suffixes)
  51      {
  52          $this->suffixes = $a_suffixes;
  53      }
  54  
  55      /**
  56      * Get Accepted Suffixes.
  57      *
  58      * @return    array    Accepted Suffixes
  59      */
  60  	function getSuffixes()
  61      {
  62          return $this->suffixes;
  63      }
  64      
  65      /**
  66      * Set hide images.
  67      *
  68      * @param    bool    $a_hide    Hide images
  69      */
  70  	function setHideImages($a_hide)
  71      {
  72          $this->hideImages = $a_hide;
  73      }
  74  
  75      /**
  76      * Set Values
  77      *
  78      * @param    array    $a_value    Value
  79      */
  80  	function setValues($a_values)
  81      {
  82          $this->values = $a_values;
  83      }
  84  
  85      /**
  86      * Get Values
  87      *
  88      * @return    array    Values
  89      */
  90  	function getValues()
  91      {
  92          return $this->values;
  93      }
  94  
  95  	function setTextName($a_value)
  96      {
  97          $this->text_name = $a_value;
  98      }
  99      
 100  	function setImageName($a_value)
 101      {
 102          $this->image_name = $a_value;
 103      }
 104      
 105      /**
 106      * Set question object
 107      *
 108      * @param    object    $a_value    test object
 109      */
 110  	function setQuestionObject($a_value)
 111      {
 112          $this->qstObject =& $a_value;
 113      }
 114  
 115      /**
 116      * Get question object
 117      *
 118      * @return    object    Value
 119      */
 120  	function getQuestionObject()
 121      {
 122          return $this->qstObject;
 123      }
 124  
 125      /**
 126      * Set allow move
 127      *
 128      * @param    boolean    $a_allow_move Allow move
 129      */
 130  	function setAllowMove($a_allow_move)
 131      {
 132          $this->allowMove = $a_allow_move;
 133      }
 134  
 135      /**
 136      * Get allow move
 137      *
 138      * @return    boolean    Allow move
 139      */
 140  	function getAllowMove()
 141      {
 142          return $this->allowMove;
 143      }
 144  
 145      /**
 146      * Set Value.
 147      *
 148      * @param    string    $a_value    Value
 149      */
 150  	function setValue($a_value)
 151      {
 152          $this->values = array();
 153          if (is_array($a_value))
 154          {
 155              if (is_array($a_value['answer']))
 156              {
 157                  foreach ($a_value['answer'] as $index => $value)
 158                  {
 159                      include_once  "./Modules/TestQuestionPool/classes/class.assAnswerMatchingTerm.php";
 160                      $answer = new assAnswerMatchingTerm($value, $a_value['imagename'][$index], $a_value['identifier'][$index]);
 161                      array_push($this->values, $answer);
 162                  }
 163              }
 164          }
 165      }
 166  
 167      /**
 168      * Check input, strip slashes etc. set alert, if input is not ok.
 169      *
 170      * @return    boolean        Input ok, true/false
 171      */    
 172  	function checkInput()
 173      {
 174          global $lng;
 175          include_once  "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
 176          if (is_array($_POST[$this->getPostVar()]))
 177          {
 178              $_POST[$this->getPostVar()] = ilUtil::stripSlashesRecursive($_POST[$this->getPostVar()], true, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("assessment"));
 179          }
 180          $foundvalues = $_POST[$this->getPostVar()];
 181          if (is_array($foundvalues))
 182          {
 183              // check answers
 184              if (is_array($foundvalues['answer']))
 185              {
 186                  foreach ($foundvalues['answer'] as $aidx => $answervalue)
 187                  {
 188                      if (((strlen($answervalue)) == 0) && (strlen($foundvalues['imagename'][$aidx]) == 0))
 189                      {
 190                          $this->setAlert($lng->txt("msg_input_is_required"));
 191                          return FALSE;
 192                      }
 193                  }
 194              }
 195              if (!$this->hideImages)
 196              {
 197                  if (is_array($_FILES[$this->getPostVar()]['error']['image']))
 198                  {
 199                      foreach ($_FILES[$this->getPostVar()]['error']['image'] as $index => $error)
 200                      {
 201                          // error handling
 202                          if ($error > 0)
 203                          {
 204                              switch ($error)
 205                              {
 206                                  case UPLOAD_ERR_INI_SIZE:
 207                                      $this->setAlert($lng->txt("form_msg_file_size_exceeds"));
 208                                      return false;
 209                                      break;
 210  
 211                                  case UPLOAD_ERR_FORM_SIZE:
 212                                      $this->setAlert($lng->txt("form_msg_file_size_exceeds"));
 213                                      return false;
 214                                      break;
 215  
 216                                  case UPLOAD_ERR_PARTIAL:
 217                                      $this->setAlert($lng->txt("form_msg_file_partially_uploaded"));
 218                                      return false;
 219                                      break;
 220  
 221                                  case UPLOAD_ERR_NO_FILE:
 222                                      if ($this->getRequired())
 223                                      {
 224                                          if ((!strlen($foundvalues['imagename'][$index])) && (!strlen($foundvalues['answer'][$index])))
 225                                          {
 226                                              $this->setAlert($lng->txt("form_msg_file_no_upload"));
 227                                              return false;
 228                                          }
 229                                      }
 230                                      break;
 231  
 232                                  case UPLOAD_ERR_NO_TMP_DIR:
 233                                      $this->setAlert($lng->txt("form_msg_file_missing_tmp_dir"));
 234                                      return false;
 235                                      break;
 236  
 237                                  case UPLOAD_ERR_CANT_WRITE:
 238                                      $this->setAlert($lng->txt("form_msg_file_cannot_write_to_disk"));
 239                                      return false;
 240                                      break;
 241  
 242                                  case UPLOAD_ERR_EXTENSION:
 243                                      $this->setAlert($lng->txt("form_msg_file_upload_stopped_ext"));
 244                                      return false;
 245                                      break;
 246                              }
 247                          }
 248                      }
 249                  }
 250  
 251                  if (is_array($_FILES[$this->getPostVar()]['tmp_name']['image']))
 252                  {
 253                      foreach ($_FILES[$this->getPostVar()]['tmp_name']['image'] as $index => $tmpname)
 254                      {
 255                          $filename = $_FILES[$this->getPostVar()]['name']['image'][$index];
 256                          $filename_arr = pathinfo($filename);
 257                          $suffix = $filename_arr["extension"];
 258  
 259                          // check suffixes
 260                          if (strlen($tmpname) && is_array($this->getSuffixes()))
 261                          {
 262                              $vir = ilUtil::virusHandling($tmpname, $filename);
 263                              if ($vir[0] == false)
 264                              {
 265                                  $this->setAlert($lng->txt("form_msg_file_virus_found")."<br />".$vir[1]);
 266                                  return false;
 267                              }
 268                              
 269                              if (!in_array(strtolower($suffix), $this->getSuffixes()))
 270                              {
 271                                  $this->setAlert($lng->txt("form_msg_file_wrong_file_type"));
 272                                  return false;
 273                              }
 274                          }
 275                      }
 276                  }
 277              }
 278          }
 279          else
 280          {
 281              $this->setAlert($lng->txt("msg_input_is_required"));
 282              return FALSE;
 283          }
 284          return $this->checkSubItemsInput();
 285      }
 286  
 287      /**
 288      * Insert property html
 289      *
 290      * @return    int    Size
 291      */
 292  	function insert(&$a_tpl)
 293      {
 294          global $lng;
 295          
 296          $tpl = new ilTemplate("tpl.prop_matchingwizardinput.html", true, true, "Modules/TestQuestionPool");
 297          $i = 0;
 298          foreach ($this->values as $value)
 299          {
 300              if (!$this->hideImages)
 301              {
 302                  if (strlen($value->picture))
 303                  {
 304                      $imagename = $this->qstObject->getImagePathWeb() . $value->picture;
 305                      if ($this->qstObject->getThumbSize())
 306                      {
 307                          if (@file_exists($this->qstObject->getImagePath() . $this->qstObject->getThumbPrefix() . $value->picture))
 308                          {
 309                              $imagename = $this->qstObject->getImagePathWeb() . $this->qstObject->getThumbPrefix() . $value->picture;
 310                          }
 311                      }
 312                      $tpl->setCurrentBlock('image');
 313                      $tpl->setVariable('SRC_IMAGE', $imagename);
 314                      $tpl->setVariable('IMAGE_NAME', $value->picture);
 315                      $tpl->setVariable('ALT_IMAGE', ilUtil::prepareFormOutput($value->text));
 316                      $tpl->setVariable("TXT_DELETE_EXISTING", $lng->txt("delete_existing_file"));
 317                      $tpl->setVariable("IMAGE_ROW_NUMBER", $i);
 318                      $tpl->setVariable("IMAGE_POST_VAR", $this->getPostVar());
 319                      $tpl->parseCurrentBlock();
 320                  }
 321                  $tpl->setCurrentBlock('addimage');
 322                  $tpl->setVariable("IMAGE_ID", $this->getPostVar() . "[image][$i]");
 323                  $tpl->setVariable("IMAGE_SUBMIT", $lng->txt("upload"));
 324                  $tpl->setVariable("IMAGE_ROW_NUMBER", $i);
 325                  $tpl->setVariable("IMAGE_POST_VAR", $this->getPostVar());
 326                  $tpl->parseCurrentBlock();
 327              }
 328  
 329              if (is_object($value))
 330              {
 331                  $tpl->setCurrentBlock("prop_text_propval");
 332                  $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->text));
 333                  $tpl->parseCurrentBlock();
 334              }
 335              // this block does not exist in the template
 336  //            $tpl->setCurrentBlock('singleline');
 337              $tpl->setVariable("SIZE", $this->getSize());
 338              $tpl->setVariable("SINGLELINE_ID", $this->getPostVar() . "[answer][$i]");
 339              $tpl->setVariable("SINGLELINE_ROW_NUMBER", $i);
 340              $tpl->setVariable("SINGLELINE_POST_VAR", $this->getPostVar());
 341              $tpl->setVariable("MAXLENGTH", $this->getMaxLength());
 342              if ($this->getDisabled())
 343              {
 344                  $tpl->setVariable("DISABLED_SINGLELINE", " disabled=\"disabled\"");
 345              }
 346              $tpl->parseCurrentBlock();
 347              if ($this->getAllowMove())
 348              {
 349                  $tpl->setCurrentBlock("move");
 350                  $tpl->setVariable("CMD_UP", "cmd[up" . $this->getFieldId() . "][$i]");
 351                  $tpl->setVariable("CMD_DOWN", "cmd[down" . $this->getFieldId() . "][$i]");
 352                  $tpl->setVariable("ID", $this->getPostVar() . "[$i]");
 353                  $tpl->setVariable("UP_BUTTON", ilUtil::getImagePath('a_up.png'));
 354                  $tpl->setVariable("DOWN_BUTTON", ilUtil::getImagePath('a_down.png'));
 355                  $tpl->parseCurrentBlock();
 356              }
 357              $tpl->setCurrentBlock("row");
 358              $class = ($i % 2 == 0) ? "even" : "odd";
 359              if ($i == 0) $class .= " first";
 360              if ($i == count($this->values)-1) $class .= " last";
 361              $tpl->setVariable("ROW_CLASS", $class);
 362              $tpl->setVariable("POST_VAR", $this->getPostVar());
 363              $tpl->setVariable("ROW_NUMBER", $i+1);
 364              $tpl->setVariable("ROW_IDENTIFIER", $value->identifier);
 365              $tpl->setVariable("ID", $this->getPostVar() . "[answer][$i]");
 366              $tpl->setVariable("CMD_ADD", "cmd[add" . $this->getFieldId() . "][$i]");
 367              $tpl->setVariable("CMD_REMOVE", "cmd[remove" . $this->getFieldId() . "][$i]");
 368              $tpl->setVariable("ADD_BUTTON", ilUtil::getImagePath('edit_add.png'));
 369              $tpl->setVariable("REMOVE_BUTTON", ilUtil::getImagePath('edit_remove.png'));
 370              $tpl->parseCurrentBlock();
 371              $i++;
 372          }
 373  
 374          if (!$this->hideImages)
 375          {
 376              if (is_array($this->getSuffixes()))
 377              {
 378                  $suff_str = $delim = "";
 379                  foreach($this->getSuffixes() as $suffix)
 380                  {
 381                      $suff_str.= $delim.".".$suffix;
 382                      $delim = ", ";
 383                  }
 384                  $tpl->setCurrentBlock('allowed_image_suffixes');
 385                  $tpl->setVariable("TXT_ALLOWED_SUFFIXES", $lng->txt("file_allowed_suffixes")." ".$suff_str);
 386                  $tpl->parseCurrentBlock();
 387              }
 388              $tpl->setCurrentBlock("image_heading");
 389              $tpl->setVariable("ANSWER_IMAGE", $this->image_name);
 390              $tpl->setVariable("TXT_MAX_SIZE", ilUtil::getFileSizeInfo());
 391              $tpl->parseCurrentBlock();
 392          }
 393  
 394          $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
 395          $tpl->setVariable("TEXT_YES", $lng->txt('yes'));
 396          $tpl->setVariable("TEXT_NO", $lng->txt('no'));
 397          $tpl->setVariable("DELETE_IMAGE_HEADER", $lng->txt('delete_image_header'));
 398          $tpl->setVariable("DELETE_IMAGE_QUESTION", $lng->txt('delete_image_question'));
 399          $tpl->setVariable("ANSWER_TEXT", $this->text_name);
 400          $tpl->setVariable("NUMBER_TEXT", $lng->txt('row'));
 401          $tpl->setVariable("COMMANDS_TEXT", $lng->txt('actions'));
 402  
 403          $a_tpl->setCurrentBlock("prop_generic");
 404          $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
 405          $a_tpl->parseCurrentBlock();
 406          /*
 407          global $tpl;
 408          include_once "./Services/YUI/classes/class.ilYuiUtil.php";
 409          ilYuiUtil::initDomEvent();
 410          $tpl->addJavascript("./Modules/TestQuestionPool/templates/default/matchingwizard.js");*/
 411      }
 412  }

title

Description

title

Description

title

Description

title

title

Body