/**
  * insert check terms into language_text and update according record in table "checks"
  * @access  private
  * @param   $checkID
  *          $term      : term to create/update into 'language_text' table
  *          $text      : text to create/update into 'language_text' table
  *          $fieldName : field name in table 'checks' to update
  * @return  true    if update successfully
  *          false   if update unsuccessful
  * @author  Cindy Qi Li
  */
 private function updateLang($checkID, $term, $text, $fieldName)
 {
     global $addslashes;
     require_once AC_INCLUDE_PATH . 'classes/DAO/LanguageTextDAO.class.php';
     $langTextDAO = new LanguageTextDAO();
     $langs = $langTextDAO->getByTermAndLang($term, $_SESSION['lang']);
     if (is_array($langs)) {
         // term already exists. Only need to update modified text
         if ($langs[0]['text'] != $addslashes($text)) {
             $langTextDAO->setText($_SESSION['lang'], '_check', $term, $text);
         }
     } else {
         $langTextDAO->Create($_SESSION['lang'], '_check', $term, $text, '');
         $sql = "UPDATE " . TABLE_PREFIX . "checks SET " . $fieldName . "='" . $term . "' WHERE check_id=" . $checkID;
         $this->execute($sql);
     }
     return true;
 }
 /**
  * Update an existing guideline
  * @access  public
  * @param   $guidelineID
  *          $userID : user id
  *          $title
  *          $abbr
  *          $long_name
  *          $published_date
  *          $earlid
  *          $preamble
  *          $status
  *          $open_to_public
  * @return  true : if successful
  *          false : if not successful
  * @author  Cindy Qi Li
  */
 public function update($guidelineID, $userID, $title, $abbr, $long_name, $published_date, $earlid, $preamble, $status, $open_to_public)
 {
     global $addslashes;
     $guidelineID = intval($guidelineID);
     $userID = intval($userID);
     $title = $addslashes(trim($title));
     $abbr = $addslashes(trim($abbr));
     $long_name = trim($long_name);
     // $addslashes is not necessary as it's called in LanguageTextDAO->setText()
     $earlid = $addslashes(trim($earlid));
     $preamble = $addslashes(trim($preamble));
     if (!$this->isFieldsValid($title, $abbr, false, $guidelineID)) {
         return false;
     }
     $sql = "UPDATE " . TABLE_PREFIX . "guidelines\n\t\t\t\t   SET `user_id`=" . $userID . ", \n\t\t\t\t       `title` = '" . $title . "', \n\t\t\t\t       `abbr` = '" . $abbr . "', \n\t\t\t\t       `published_date` = '" . $published_date . "',  \n\t\t\t\t       `earlid` = '" . $earlid . "', \n\t\t\t\t       `preamble` = '" . $preamble . "', \n\t\t\t\t       `status` = " . $status . ", \n\t\t\t\t       `open_to_public` = " . $open_to_public . " \n\t\t\t\t WHERE guideline_id = " . $guidelineID;
     if (!$this->execute($sql)) {
         $msg->addError('DB_NOT_UPDATED');
         return false;
     } else {
         // find language term to update
         $rows = $this->getGuidelineByIDs($guidelineID);
         $term = $rows[0]['long_name'];
         require_once AC_INCLUDE_PATH . 'classes/DAO/LanguageTextDAO.class.php';
         $langTextDAO = new LanguageTextDAO();
         if ($langTextDAO->setText($_SESSION['lang'], '_guideline', $term, $long_name)) {
             return true;
         } else {
             return false;
         }
     }
 }