Example #1
0
/**
 * Returns table row(s) for edit of an admin user's custom data
 *
 * @param string $html always empty
 * @param $userobj Admin user object
 * @param string $i prefix for the admin
 * @param string $background background color for the admin row
 * @param bool $current true if this admin row is the logged in admin
 * @return string
 */
function user_groups_edit_admin($html, $userobj, $i, $background, $current)
{
    global $gallery, $_zp_authority, $_zp_zenpage;
    $group = $userobj->getGroup();
    $admins = $_zp_authority->getAdministrators('all');
    $ordered = array();
    $groups = array();
    $hisgroup = NULL;
    $adminordered = array();
    foreach ($admins as $key => $admin) {
        $ordered[$key] = $admin['user'];
        if ($group == $admin['user']) {
            $hisgroup = $admin;
        }
    }
    asort($ordered);
    foreach ($ordered as $key => $user) {
        $adminordered[] = $admins[$key];
        if (!$admins[$key]['valid']) {
            $groups[] = $admins[$key];
        }
    }
    if (empty($groups)) {
        return '';
    }
    // no groups setup yet
    if (zp_loggedin(ADMIN_RIGHTS)) {
        $albumlist = array();
        $allalb = array();
        foreach ($gallery->getAlbums() as $folder) {
            if (hasDynamicAlbumSuffix($folder)) {
                $name = substr($folder, 0, -4);
                // Strip the .'.alb' suffix
            } else {
                $name = $folder;
            }
            $albumlist[$name] = $folder;
            $allalb[] = "'#managed_albums_" . $i . '_' . postIndexEncode($folder) . "'";
        }
        if (getOption('zp_plugin_zenpage')) {
            $pagelist = array();
            $allpag = array();
            $pages = $_zp_zenpage->getPages(false);
            foreach ($pages as $page) {
                if (!$page['parentid']) {
                    $pagelist[get_language_string($page['title'])] = $page['titlelink'];
                    $allpag[] = "'#managed_pages_" . $i . '_' . postIndexEncode($page['titlelink']) . "'";
                }
            }
            $newslist = array();
            $allnew = array();
            $categories = $_zp_zenpage->getAllCategories(false);
            foreach ($categories as $category) {
                $newslist[get_language_string($category['titlelink'])] = $category['title'];
                $allnew[] = "'#managed_news_" . $i . '_' . postIndexEncode($category['titlelink']) . "'";
            }
        }
        $rights = array();
        foreach ($_zp_authority->getRights() as $rightselement => $right) {
            if ($right['display']) {
                $rights[] = "'#" . $rightselement . '-' . $i . "'";
            }
        }
        $grouppart = '
			<script type="text/javascript">
				// <!-- <![CDATA[
				function groupchange' . $i . '(obj) {
					var disable = obj.value != \'\';
					var albdisable = false;
					var checkedalbums = [];
					var checked = 0;
					var uncheckedalbums = [];
					var unchecked = 0;
					var allalbums = [' . implode(',', $allalb) . '];
					var allalbumsc = ' . count($allalb) . ';';
        if (getOption('zp_plugin_zenpage')) {
            $grouppart .= '
						var allpages = [' . implode(',', $allpag) . '];
						var allpagesc = ' . count($allpag) . ';
						var allnews = [' . implode(',', $allnew) . '];
						var allnewsc = ' . count($allnew) . ';';
        }
        $grouppart .= '
					var rights = [' . implode(',', $rights) . '];
					var rightsc = ' . count($rights) . ';
					for (i=0;i<rightsc;i++) {
						$(rights[i]).attr(\'disabled\',disable);
					}
					for (i=0;i<allalbumsc;i++) {
						$(allalbums[i]).attr(\'disabled\',disable);
					}';
        if (getOption('zp_plugin_zenpage')) {
            $grouppart .= '
					for (i=0;i<allpagesc;i++) {
						$(allpages[i]).attr(\'disabled\',disable);
					}
					for (i=0;i<allnewsc;i++) {
						$(allnews[i]).attr(\'disabled\',disable);
					}';
        }
        $grouppart .= '
					$(\'#hint' . $i . '\').html(obj.options[obj.selectedIndex].title);
					if (disable) {
						switch (obj.value) {';
        foreach ($groups as $user) {
            $grouppart .= '
							case \'' . $user['user'] . '\':
								target = ' . $user['rights'] . ';';
            if (getOption('zp_plugin_zenpage')) {
                $codelist = array('album', 'pages', 'news');
            } else {
                $codelist = array('album');
            }
            foreach ($codelist as $mo) {
                $cv = populateManagedObjectsList($mo, $user['id']);
                switch ($mo) {
                    case 'album':
                        $xv = array_diff($albumlist, $cv);
                        break;
                    case 'pages':
                        $xv = array_diff($pagelist, $cv);
                        break;
                    case 'news':
                        $xv = array_diff($newslist, $cv);
                        break;
                }
                $cvo = array();
                foreach ($cv as $moid) {
                    $cvo[] = "'#managed_" . $mo . "_" . $i . '_' . postIndexEncode($moid) . "'";
                }
                $xvo = array();
                foreach ($xv as $moid) {
                    $xvo[] = "'#managed_" . $mo . "_" . $i . '_' . postIndexEncode($moid) . "'";
                }
                $grouppart .= '
									checked' . $mo . ' = [' . implode(',', $cvo) . '];
									checked' . $mo . 'c = ' . count($cvo) . ';
									unchecked' . $mo . ' = [' . implode(',', $xvo) . '];
									unchecked' . $mo . 'c = ' . count($xvo) . ';';
            }
            if ($user['name'] == 'template') {
                $albdisable = 'false';
            } else {
                $albdisable = 'true';
            }
            $grouppart .= '
								break;';
        }
        $grouppart .= '
							}
						for (i=0;i<checkedalbumc;i++) {
							$(checkedalbum[i]).attr(\'checked\',\'checked\');
						}
						for (i=0;i<uncheckedalbumc;i++) {
							$(uncheckedalbum[i]).attr(\'checked\',\'\');
						}';
        foreach ($groups as $user) {
            $grouppart .= '
						for (i=0;i<checkedpagesc;i++) {
							$(checkedpages[i]).attr(\'checked\',\'checked\');
						}
						for (i=0;i<uncheckedpagesc;i++) {
							$(uncheckedpages[i]).attr(\'checked\',\'\');
						}
						for (i=0;i<checkednewsc;i++) {
							$(checkednews[i]).attr(\'checked\',\'checked\');
						}
						for (i=0;i<uncheckednewsc;i++) {
							$(uncheckednews[i]).attr(\'checked\',\'\');
						}';
        }
        $grouppart .= '
						for (i=0;i<rightsc;i++) {
							if ($(rights[i]).val()&target) {
								$(rights[i]).attr(\'checked\',\'checked\');
							} else {
								$(rights[i]).attr(\'checked\',\'\');
							}
						}
					}
				}';
        if (is_array($hisgroup)) {
            $grouppart .= '
				window.onload = function() {';
            foreach ($codelist as $mo) {
                $cv = populateManagedObjectsList($mo, $user['id']);
                switch ($mo) {
                    case 'album':
                        $list = $albumlist;
                        break;
                    case 'pages':
                        $list = $pagelist;
                        break;
                    case 'news':
                        $list = $newslist;
                        break;
                }
                foreach ($list as $moid) {
                    if (in_array($moid, $cv)) {
                        $grouppart .= '
						$(\'#managed_' . $mo . '_' . $i . '_' . postIndexEncode($moid) . '\').attr(\'checked\',\'checked\');';
                    } else {
                        $grouppart .= '
						$(\'#managed_' . $mo . '_' . $i . '_' . postIndexEncode($moid) . '\').attr(\'checked\',\'\');';
                    }
                }
            }
            $grouppart .= '
				}';
        }
        $grouppart .= '
				//]]> -->
			</script>';
        $grouppart .= '<select name="' . $i . 'group" onchange="javascript:groupchange' . $i . '(this);"' . '>' . "\n";
        $grouppart .= '<option value="" title="' . gettext('*no group affiliation') . '">' . gettext('*no group selected') . '</option>' . "\n";
        $selected_hint = gettext('no group affiliation');
        foreach ($groups as $user) {
            if ($user['name'] == 'template') {
                $type = '<strong>' . gettext('Template:') . '</strong> ';
            } else {
                $type = '';
            }
            $hint = $type . '<em>' . html_encode($user['custom_data']) . '</em>';
            if ($group == $user['user']) {
                $selected = ' selected="selected"';
                $selected_hint = $hint;
            } else {
                $selected = '';
            }
            $grouppart .= '<option' . $selected . ' value="' . $user['user'] . '" title="' . sanitize($hint, 3) . '">' . $user['user'] . '</option>' . "\n";
        }
        $grouppart .= '</select>' . "\n";
        $grouppart .= '<span class="hint' . $i . '" id="hint' . $i . '" style="width:15em;">' . $selected_hint . "</span>\n";
    } else {
        if ($group) {
            $grouppart = $group;
        } else {
            $grouppart = gettext('no group affiliation');
        }
        $grouppart = ' <em>' . $grouppart . '</em><input type="hidden" name="' . $i . 'group" value="' . $group . '" />' . "\n";
    }
    $result = '<tr' . (!$current ? ' style="display:none;"' : '') . ' class="userextrainfo">
			<td colspan="2" width="20%"' . (!empty($background) ? ' style="' . $background . '"' : '') . ' valign="top">' . gettext('User group membership') . $grouppart . '<br />' . gettext('<strong>Note:</strong> When a group is assigned <em>rights</em> and <em>managed albums</em> are determined by the group!') . '</td>
			<td' . (!empty($background) ? ' style="' . $background . '"' : '') . ' valign="top" width="345">' . '</td>
			</tr>' . "\n";
    return $html . $result;
}
Example #2
0
 /**
  * Returns local copy of managed objects.
  */
 function getObjects($what = NULL, $full = NULL)
 {
     if (is_null($this->objects)) {
         if ($this->transient) {
             $this->objects = array();
         } else {
             $this->objects = populateManagedObjectsList(NULL, $this->getID());
         }
     }
     if (empty($what)) {
         return $this->objects;
     }
     $result = array();
     foreach ($this->objects as $object) {
         if ($object['type'] == $what) {
             if ($full) {
                 $result[$object['data']] = $object;
             } else {
                 $result[$object['name']] = $object['data'];
             }
         }
     }
     return $result;
 }
/**
 * Creates the managed album table for Admin
 *
 * @param string $type the kind of list
 * @param array $objlist list of objects
 * @param string $alterrights are the items changable
 * @param int $adminid ID of the admin
 * @param int $prefix the admin row
 * @param bit $rights the privileges  of the user
 */
function printManagedObjects($type, $objlist, $alterrights, $adminid, $prefix, $rights, $kind)
{
    $ledgend = '';
    switch ($type) {
        case 'albums':
            if ($rights & (MANAGE_ALL_ALBUM_RIGHTS | ADMIN_RIGHTS)) {
                $cv = $objlist;
                $rest = $extra = array();
                $alterrights = ' disabled="disabled"';
            } else {
                $full = populateManagedObjectsList('album', $adminid, true);
                $cv = $extra = array();
                $icon_edit_album = '<img src="' . WEBPATH . '/' . ZENFOLDER . '/images/edit-album.png" class="icon-position-top3" alt="" title="' . gettext('edit albums') . '" />';
                $icon_view_image = '<img src="' . WEBPATH . '/' . ZENFOLDER . '/images/action.png" class="icon-position-top3" alt="" title="' . gettext('view unpublished images') . '" />';
                $icon_upload = '<img src="' . WEBPATH . '/' . ZENFOLDER . '/images/arrow_up.png" class="icon-position-top3"  alt="" title="' . gettext('upload to album') . '"/>';
                if ($rights & ALBUM_RIGHTS) {
                    $ledgend .= $icon_edit_album . ' ' . gettext('edit album') . ' ';
                }
                if ($rights & UPLOAD_RIGHTS) {
                    $ledgend .= $icon_upload . ' ' . gettext('upload') . ' ';
                }
                if (!($rights & VIEW_ALBUMS_RIGHTS)) {
                    $ledgend .= $icon_view_image . ' ' . gettext('view unpublished images');
                }
                foreach ($full as $item) {
                    $cv[$item['name']] = $item['data'];
                    $extra[$item['data']][] = array('name' => 'default', 'value' => 0, 'display' => '', 'checked' => 1);
                    if ($rights & ALBUM_RIGHTS) {
                        $extra[$item['data']][] = array('name' => 'edit', 'value' => MANAGED_OBJECT_RIGHTS_EDIT, 'display' => $icon_edit_album, 'checked' => $item['edit'] & MANAGED_OBJECT_RIGHTS_EDIT);
                    }
                    if ($rights & UPLOAD_RIGHTS && !hasDynamicAlbumSuffix($item['data'])) {
                        $extra[$item['data']][] = array('name' => 'upload', 'value' => MANAGED_OBJECT_RIGHTS_UPLOAD, 'display' => $icon_upload, 'checked' => $item['edit'] & MANAGED_OBJECT_RIGHTS_UPLOAD);
                    }
                    if (!($rights & VIEW_ALBUMS_RIGHTS)) {
                        $extra[$item['data']][] = array('name' => 'view', 'value' => MANAGED_OBJECT_RIGHTS_VIEW_IMAGE, 'display' => $icon_view_image, 'checked' => $item['edit'] & MANAGED_OBJECT_RIGHTS_VIEW_IMAGE);
                    }
                }
                $rest = array_diff($objlist, $cv);
            }
            $text = gettext("Managed albums:");
            $simplename = $objectname = gettext('Albums');
            $prefix = 'managed_albums_list_' . $prefix . '_';
            break;
        case 'news':
            if ($rights & (MANAGE_ALL_NEWS_RIGHTS | ADMIN_RIGHTS)) {
                $cv = $objlist;
                $rest = array();
                $alterrights = ' disabled="disabled"';
            } else {
                $cv = populateManagedObjectsList('news', $adminid);
                $rest = array_diff($objlist, $cv);
            }
            $text = gettext("Managed news categories:");
            $simplename = gettext('News');
            $objectname = gettext('News categories');
            $prefix = 'managed_news_list_' . $prefix . '_';
            $extra = array();
            break;
        case 'pages':
            if ($rights & (MANAGE_ALL_PAGES_RIGHTS | ADMIN_RIGHTS)) {
                $cv = $objlist;
                $rest = array();
                $alterrights = ' disabled="disabled"';
            } else {
                $cv = populateManagedObjectsList('pages', $adminid);
                $rest = array_diff($objlist, $cv);
            }
            $text = gettext("Managed pages:");
            $simplename = $objectname = gettext('Pages');
            $prefix = 'managed_pages_list_' . $prefix . '_';
            $extra = array();
            break;
    }
    if (empty($alterrights)) {
        $hint = sprintf(gettext('Select one or more %1$s for the %2$s to manage.'), $simplename, $kind) . ' ';
        if ($kind == gettext('user')) {
            $hint .= sprintf(gettext('Users with "Admin" or "Manage all %1$s" rights can manage all %2$s. All others may manage only those that are selected.'), $type, $objectname);
        }
    } else {
        $hint = sprintf(gettext('You may manage these %s subject to the above rights.'), $simplename);
    }
    if (count($cv) > 0) {
        $itemcount = ' (' . count($cv) . ')';
    } else {
        $itemcount = '';
    }
    ?>

	<div class="box-albums-unpadded">
	<h2 class="h2_bordered_albums">
	<a href="javascript:toggle('<?php 
    echo $prefix;
    ?>
');" title="<?php 
    echo html_encode($hint);
    ?>
" ><?php 
    echo $text . $itemcount;
    ?>
</a>
	</h2>
		<div id="<?php 
    echo $prefix;
    ?>
" style="display:none;">
			<ul class="albumchecklist">
				<?php 
    generateUnorderedListFromArray($cv, $cv, $prefix, $alterrights, true, true, NULL, $extra);
    generateUnorderedListFromArray(array(), $rest, $prefix, $alterrights, true, true);
    ?>
			</ul>
			<?php 
    echo $ledgend;
    ?>
		</div>
	</div>
	<?php 
}