示例#1
0
/**
 *
 **/
function toggle_active($id)
{
    global $parser, $val, $backend;
    $groups = CAT_Users::get_groups_id();
    if (!CAT_Helper_Droplet::is_allowed('modify_droplets', $groups)) {
        $backend->print_error($backend->lang()->translate("You don't have the permission to do this"));
    }
    $data = CAT_Helper_Droplet::getDroplet($id);
    $new = $data['active'] == 1 ? 0 : 1;
    $backend->db()->query('UPDATE `:prefix:mod_droplets` SET active=:active WHERE id=:id', array('active' => $new, 'id' => $id));
    return list_droplets();
}
示例#2
0
 /**
  * returns a list of droplets the current user is allowed to use
  *
  * @access public
  * @return array
  **/
 public static function getDroplets($with_code = false)
 {
     $self = self::getInstance();
     $groups = CAT_Users::get_groups_id();
     $rows = array();
     $fields = 't1.id, `name`, `description`, `active`, `comments`, `view_groups`, `edit_groups`';
     if ($with_code) {
         $fields .= ', `code`';
     }
     $query = $self->db()->query("SELECT {$fields} FROM `:prefix:mod_droplets` AS t1 " . "LEFT OUTER JOIN `:prefix:mod_droplets_permissions` AS t2 " . "ON t1.id=t2.id ORDER BY `name` ASC");
     if ($query->rowCount()) {
         while ($droplet = $query->fetch()) {
             // the current user needs global edit permissions, or specific edit permissions to see this droplet
             if (!CAT_Helper_Droplet::is_allowed('modify_droplets', $groups)) {
                 // get edit groups for this drople
                 if ($droplet['edit_groups']) {
                     if (CAT_Users::get_user_id() != 1 && !is_in_array($droplet['edit_groups'], $groups)) {
                         continue;
                     } else {
                         $droplet['user_can_modify_this'] = true;
                     }
                 }
             }
             $comments = str_replace(array("\r\n", "\n", "\r"), '<br />', $droplet['comments']);
             if (!strpos($comments, "[[")) {
                 $comments = '<span class="usage">' . $self->lang()->translate('Use') . ": [[" . $droplet['name'] . "]]</span><br />" . $comments;
             }
             $comments = str_replace(array("[[", "]]"), array('<b>[[', ']]</b>'), $comments);
             if ($with_code) {
                 $droplet['valid_code'] = self::check_syntax($droplet['code']);
             }
             $droplet['comments'] = $comments;
             // droplet included in search?
             //$droplet['is_in_search'] = self::is_registered_droplet_search($droplet['name']);
             // is there a data file for this droplet?
             if (file_exists(dirname(__FILE__) . '/data/' . $droplet['name'] . '.txt') || file_exists(dirname(__FILE__) . '/data/' . strtolower($droplet['name']) . '.txt') || file_exists(dirname(__FILE__) . '/data/' . strtoupper($droplet['name']) . '.txt')) {
                 $droplet['datafile'] = true;
             }
             array_push($rows, $droplet);
         }
     }
     return $rows;
 }