示例#1
0
 public function delete()
 {
     $id = awpcp_request_param('id', 0);
     $fee = AWPCP_Fee::find_by_id($id);
     if (is_null($fee)) {
         awpcp_flash(__("The specified Fee doesn't exists.", 'AWPCP'), 'error');
         return $this->index();
     }
     $errors = array();
     if (AWPCP_Fee::delete($fee->id, $errors)) {
         awpcp_flash(__('The Fee was successfully deleted.', 'AWPCP'));
     } else {
         $where = sprintf("adterm_id = %d AND payment_term_type = 'fee'", $fee->id);
         $ads = AWPCP_Ad::find($where);
         if (empty($ads)) {
             foreach ($errors as $error) {
                 awpcp_flash($error, 'error');
             }
         } else {
             $fees = AWPCP_Fee::query();
             if (count($fees) > 1) {
                 $message = __("The Fee couldn't be deleted because there are active Ads in the system that are associated with the Fee ID. You need to switch the Ads to a different Fee before you can delete the plan.", "AWPCP");
                 awpcp_flash($message, 'error');
                 $params = array('fee' => $fee, 'fees' => $fees);
                 $template = AWPCP_DIR . '/admin/templates/admin-panel-fees-delete.tpl.php';
                 echo $this->render($template, $params);
                 return;
             } else {
                 $message = __("The Fee couldn't be deleted because there are active Ads in the system that are associated with the Fee ID. Please create a new Fee and try the delete operation again. AWPCP will help you to switch existing Ads to the new fee.", "AWPCP");
                 awpcp_flash($message, 'error');
             }
         }
     }
     return $this->index();
 }