/**
  * Outputs a list of all posts alerted by users.
  *
  * This function output a list of all post alerts submitted by users.
  * It allows a filtering by post alert status and different ordering options.
  * @param  array  $conf The calling plugin's configuration vars
  * @return string       The post alert list
  */
 function list_alerts($conf)
 {
     $param = GeneralUtility::_GP('tx_mmforum_pi1');
     if ($param['update'] == 'update_status') {
         foreach ($param as $key => $value) {
             $key = str_replace('status_', '', $key);
             if (is_numeric($key)) {
                 $key = $this->databaseHandle->fullQuoteStr($key, 'tx_mmforum_post_alert');
                 $value = $this->databaseHandle->fullQuoteStr($value, 'tx_mmforum_post_alert');
                 $updateArray = array('status' => $value, 'tstamp' => $GLOBALS['EXEC_TIME']);
                 $this->databaseHandle->exec_UPDATEquery('tx_mmforum_post_alert', 'uid=' . $key . ' AND status <> ' . $value, $updateArray);
             }
         }
     }
     $template = $this->cObj->fileResource($conf['template.']['post_alert']);
     $template = $this->cObj->getSubpart($template, "###ALERT_LIST###");
     $template_sub = $this->cObj->getSubpart($template, "###ALERT_LIST_SUB###");
     // Language dependent markers
     $marker = array('###LABEL_POSTALERTS###' => $this->pi_getLL('postalert.title'), '###LABEL_ORDERBY###' => $this->pi_getLL('postalert.orderby'), '###LABEL_ORDERBY_STATUS###' => $this->pi_getLL('postalert.orderby.status'), '###LABEL_ORDERBY_DATE###' => $this->pi_getLL('postalert.orderby.date'), '###LABEL_ORDERBY_USER###' => $this->pi_getLL('postalert.orderby.user'), '###LABEL_ORDERASC###' => $this->pi_getLL('postalert.ordermode.asc'), '###LABEL_ORDERDESC###' => $this->pi_getLL('postalert.ordermode.desc'), '###LABEL_DISPLAY###' => $this->pi_getLL('postalert.display'), '###LABEL_OPEN###' => $this->pi_getLL('postalert.status.open'), '###LABEL_INPROGRESS###' => $this->pi_getLL('postalert.status.progress'), '###LABEL_DONE###' => $this->pi_getLL('postalert.status.done'), '###LABEL_NR###' => $this->pi_getLL('postalert.number'), '###LABEL_DATE###' => $this->pi_getLL('postalert.date'), '###LABEL_PROBLEM###' => $this->pi_getLL('postalert.problem'), '###LABEL_POST###' => $this->pi_getLL('postalert.post'), '###LABEL_USER###' => $this->pi_getLL('postalert.user'), '###LABEL_STATUS###' => $this->pi_getLL('postalert.status'), '###LABEL_POSTTEXT###' => $this->pi_getLL('postalert.posttext'));
     $marker['###ORDERBY_USER###'] = '';
     $marker['###ORDERBY_DATE###'] = '';
     $marker['###ORDERBY_STAT###'] = '';
     $marker['###ORDERASC###'] = '';
     $marker['###ORDERDESC###'] = '';
     $marker['###VIEW_OPEN###'] = '';
     $marker['###VIEW_WORK###'] = '';
     $marker['###VIEW_CLOSE###'] = '';
     // Determine ordering mode
     switch ($param['order_by']) {
         case "user":
             $order_by = 'cruser_id';
             $marker['###ORDERBY_USER###'] = 'selected';
             break;
         case "date":
             $order_by = 'crdate';
             $marker['###ORDERBY_DATE###'] = 'selected';
             break;
         case "status":
             $order_by = 'status';
             $marker['###ORDERBY_STAT###'] = 'selected';
             break;
         default:
             $order_by = 'status';
             $marker['###ORDERBY_STAT###'] = 'selected';
             break;
     }
     switch ($param['order']) {
         case "up":
             $order = 'ASC';
             $marker['###ORDERASC###'] = 'selected';
             break;
         case "down":
             $order = 'DESC';
             $marker['###ORDERDESC###'] = 'selected';
             break;
         default:
             $order = 'ASC';
             $marker['###ORDERASC###'] = 'selected';
             break;
     }
     $allowedStatus = array();
     // Determine filtering mode
     if ($param['view_open'] == 1) {
         $marker['###VIEW_OPEN###'] = 'checked';
         #$where .= 'OR status = -1 ';
         $allowedStatus[] = -1;
     }
     if ($param['view_work'] == 1) {
         $marker['###VIEW_WORK###'] = 'checked';
         #$where .= 'OR status = 0 ';= -1 ';
         $allowedStatus[] = 0;
     }
     if ($param['view_close'] == 1) {
         $marker['###VIEW_CLOSE###'] = 'checked';
         #$where .= 'OR status = 1 ';= -1 ';
         $allowedStatus[] = 1;
     }
     if ($param['view_close'] == '' and $param['view_work'] == '' and $param['view_open'] == '' and empty($param)) {
         $marker['###VIEW_OPEN###'] = 'checked';
         $marker['###VIEW_WORK###'] = 'checked';
         $marker['###VIEW_CLOSE###'] = '';
         #$where = ' OR status = -1 OR status = 0';
         $allowedStatus = array(0, -1);
     }
     $where = count($allowedStatus) ? ' AND status IN (' . implode(',', $allowedStatus) . ') ' : '';
     $boards = tx_mmforum_postalert::getModeratorBoards();
     if ($boards === false) {
         $accessWhere = ' AND 0=1 ';
     } elseif ($boards === true) {
         $accessWhere = ' AND 1=1 ';
     } else {
         $accessWhere = ' AND t.forum_id IN (' . implode(',', $boards) . ') ';
     }
     // Load post alert records from database
     $res = $this->databaseHandle->exec_SELECTquery('a.*', 'tx_mmforum_post_alert a LEFT JOIN tx_mmforum_topics t ON a.topic_id = t.uid', "1 = 1 {$where} {$accessWhere}", '', $order_by . ' ' . $order);
     $content_sub = '';
     while ($row = $this->databaseHandle->sql_fetch_assoc($res)) {
         $marker['###STATUS###'] = '';
         switch ($row['status']) {
             case '-1':
                 $marker['###STATCOLOR###'] = $this->conf['postalerts.']['statusColors.']['open'];
                 $marker['###STATUS###'] .= '<option value="-1" selected>' . $this->pi_getLL('postalert.status.open') . '</option>';
                 $marker['###STATUS###'] .= '<option value="0">' . $this->pi_getLL('postalert.status.progress') . '</option>';
                 $marker['###STATUS###'] .= '<option value="1">' . $this->pi_getLL('postalert.status.done') . '</option>';
                 break;
             case '0':
                 $marker['###STATCOLOR###'] = $this->conf['postalerts.']['statusColors.']['work'];
                 $marker['###STATUS###'] .= '<option value="-1">' . $this->pi_getLL('postalert.status.open') . '</option>';
                 $marker['###STATUS###'] .= '<option value="0" selected>' . $this->pi_getLL('postalert.status.progress') . '</option>';
                 $marker['###STATUS###'] .= '<option value="1">' . $this->pi_getLL('postalert.status.done') . '</option>';
                 break;
             case '1':
                 $marker['###STATCOLOR###'] = $this->conf['postalerts.']['statusColors.']['done'];
                 $marker['###STATUS###'] .= '<option value="-1">' . $this->pi_getLL('postalert.status.open') . '</option>';
                 $marker['###STATUS###'] .= '<option value="0">' . $this->pi_getLL('postalert.status.progress') . '</option>';
                 $marker['###STATUS###'] .= '<option value="1" selected>' . $this->pi_getLL('postalert.status.done') . '</option>';
                 break;
         }
         $linkparams[$this->prefixId] = array('action' => 'list_post', 'tid' => $row['topic_id'], 'pid' => $row['post_id']);
         list($posttext) = $this->databaseHandle->sql_fetch_row($this->databaseHandle->exec_SELECTquery('post_text', 'tx_mmforum_posts_text', 'deleted="0" AND hidden="0" AND post_id="' . $row['post_id'] . '"'));
         $marker['###UID###'] = $row['uid'];
         $marker['###TOPIC###'] = $this->pi_linkToPage($this->escape($this->get_topic_name($row['topic_id'])), $conf['pid_forum'], $target = '_self', $linkparams);
         $marker['###DATE###'] = $this->formatDate($row['crdate']);
         $marker['###POST_TEXT###'] = nl2br($this->escape($posttext));
         $marker['###TEXT_SHORT###'] = $this->escape(tx_mmforum_tools::textCut($row['alert_text'], 15, ''));
         $marker['###TEXT###'] = nl2br($this->escape($row['alert_text']));
         $mod_data = tx_mmforum_tools::get_userdata($row['cruser_id']);
         $marker['###MOD###'] = $mod_data[$this->getUserNameField()];
         $marker['###POST_USER###'] = $this->pi_linkToPage($mod_data[$this->getUserNameField()], $conf['pm_id'], '', array('tx_mmforum_pi3[action]' => 'message_write', 'userid' => $row['cruser_id']));
         $content_sub .= $this->cObj->substituteMarkerArrayCached($template_sub, $marker);
     }
     $content = $this->cObj->substituteSubpart($template, '###ALERT_LIST_SUB###', $content_sub);
     $marker['###FORMACTION###'] = $this->escapeURL($this->pi_getPageLink($GLOBALS["TSFE"]->id, '', $linkparams));
     $content = $this->cObj->substituteMarkerArrayCached($content, $marker);
     return $content;
 }