ILIAS PHP Cross Reference Learning Management Systems

Source: /Modules/TestQuestionPool/classes/class.ilSingleChoiceWizardInputGUI.php - 515 lines - 14295 bytes - Summary - Text - Print

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

title

Description

title

Description

title

Description

title

title

Body