/**
  * Create a new guideline
  * @access  public
  * @param   $userID : user id
  *          $title
  *          $abbr
  *          $long_name
  *          $published_date
  *          $earlid
  *          $preamble
  *          $status
  *          $open_to_public
  * @return  guidelineID : if successful
  *          false : if not successful
  * @author  Cindy Qi Li
  */
 public function Create($userID, $title, $abbr, $long_name, $published_date, $earlid, $preamble, $status, $open_to_public)
 {
     global $addslashes;
     $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->Create()
     $earlid = $addslashes(trim($earlid));
     $preamble = $addslashes(trim($preamble));
     if ($published_date == '' || is_null($published_date)) {
         $published_date = '0000-00-00';
     }
     if (!$this->isFieldsValid($title, $abbr, true)) {
         return false;
     }
     $sql = "INSERT INTO " . TABLE_PREFIX . "guidelines\n\t\t\t\t(`user_id`, `title`, `abbr`, `published_date`,  \n\t\t\t\t `earlid`, `preamble`, `status`, `open_to_public`) \n\t\t\t\tVALUES\n\t\t\t\t(" . $userID . ",'" . $title . "', '" . $abbr . "', '" . $published_date . "',\n\t\t\t\t '" . $earlid . "','" . $preamble . "', " . $status . "," . $open_to_public . ")";
     if (!$this->execute($sql)) {
         $msg->addError('DB_NOT_UPDATED');
         return false;
     } else {
         $guidelineID = mysql_insert_id();
         if ($long_name != '') {
             $term = LANG_PREFIX_GUIDELINES_LONG_NAME . $guidelineID;
             require_once AC_INCLUDE_PATH . 'classes/DAO/LanguageTextDAO.class.php';
             $langTextDAO = new LanguageTextDAO();
             if ($langTextDAO->Create($_SESSION['lang'], '_guideline', $term, $long_name, '')) {
                 $sql = "UPDATE " . TABLE_PREFIX . "guidelines SET long_name='" . $term . "' WHERE guideline_id=" . $guidelineID;
                 $this->execute($sql);
             }
         }
         return $guidelineID;
     }
 }
 /**
  * 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;
 }