Exemplo n.º 1
0
function create_wiki($gid = false, $wikiName = 'New wiki')
{
    $creatorId = claro_get_current_user_id();
    $tblList = claro_sql_get_course_tbl();
    $config = array();
    $config["tbl_wiki_properties"] = $tblList["wiki_properties"];
    $config["tbl_wiki_pages"] = $tblList["wiki_pages"];
    $config["tbl_wiki_pages_content"] = $tblList["wiki_pages_content"];
    $config["tbl_wiki_acls"] = $tblList["wiki_acls"];
    $con = Claroline::getDatabase();
    $acl = array();
    if ($gid) {
        $acl = WikiAccessControl::defaultGroupWikiACL();
    } else {
        $acl = WikiAccessControl::defaultCourseWikiACL();
    }
    $wiki = new Wiki($con, $config);
    $wiki->setTitle($wikiName);
    $wiki->setDescription('This is a sample wiki');
    $wiki->setACL($acl);
    $wiki->setGroupId($gid);
    $wikiId = $wiki->save();
    $wikiTitle = $wiki->getTitle();
    $mainPageContent = sprintf("This is the main page of the Wiki %s. Click on edit to modify the content.", $wikiTitle);
    $wikiPage = new WikiPage($con, $config, $wikiId);
    $wikiPage->create($creatorId, '__MainPage__', $mainPageContent, date("Y-m-d H:i:s"), true);
}
Exemplo n.º 2
0
        $is_allowedToRead = $is_editor || $is_groupMember && WikiAccessControl::isAllowedToReadPage($accessControlList, 'group') || $is_courseMember && WikiAccessControl::isAllowedToReadPage($accessControlList, 'course') || WikiAccessControl::isAllowedToReadPage($accessControlList, 'other');
        $is_allowedToEdit = $is_editor || $is_groupMember && WikiAccessControl::isAllowedToEditPage($accessControlList, 'group') || $is_courseMember && WikiAccessControl::isAllowedToEditPage($accessControlList, 'course') || WikiAccessControl::isAllowedToEditPage($accessControlList, 'other');
        $is_allowedToCreate = $is_editor || $is_groupMember && WikiAccessControl::isAllowedToCreatePage($accessControlList, 'group') || $is_courseMember && WikiAccessControl::isAllowedToCreatePage($accessControlList, 'course') || WikiAccessControl::isAllowedToCreatePage($accessControlList, 'other');
    }
} else {
    // course context
    if (is_array($accessControlList)) {
        // course member
        if ($is_courseMember) {
            $is_allowedToRead = $is_editor || WikiAccessControl::isAllowedToReadPage($accessControlList, 'course');
            $is_allowedToEdit = $is_editor || WikiAccessControl::isAllowedToEditPage($accessControlList, 'course');
            $is_allowedToCreate = $is_editor || WikiAccessControl::isAllowedToCreatePage($accessControlList, 'course');
        } else {
            $is_allowedToRead = $is_editor || WikiAccessControl::isAllowedToReadPage($accessControlList, 'other');
            $is_allowedToEdit = $is_editor || WikiAccessControl::isAllowedToEditPage($accessControlList, 'other');
            $is_allowedToCreate = $is_editor || WikiAccessControl::isAllowedToCreatePage($accessControlList, 'other');
        }
    }
}
// --------------- End of  access rights management ----------------
// filter action
if ($is_allowedToEdit || $is_allowedToCreate) {
    $valid_actions = array("edit", "preview", "save", "delete", "show", "recent", "diff", "all", "history", "rqSearch", "exSearch");
} else {
    $valid_actions = array("show", "recent", "diff", "all", "history", "rqSearch", "exSearch");
}
$_CLEAN = filter_by_key('action', $valid_actions, "R", false);
$action = isset($_CLEAN['action']) ? $_CLEAN['action'] : 'show';
// get request variables
$creatorId = $uid;
$versionId = isset($_REQUEST['versionId']) ? intval($_REQUEST['versionId']) : 0;
Exemplo n.º 3
0
/**
 * Generate html code of Wiki properties edit form
 * @param int wikiId ID of the wiki
 * @param string title wiki tile
 * @param string desc wiki description
 * @param int groupId id of the group the wiki belongs to
 *      (0 for a course wiki)
 * @param array acl wiki access control list
 * @param string script callback script url
 * @return string html code of the wiki properties form
 */
function claro_disp_wiki_properties_form($wikiId = 0, $title = '', $desc = '', $groupId = 0, $acl = null, $script = null)
{
    global $langWikiDescriptionForm, $langWikiDescriptionFormText, $langWikiTitle, $langWikiDescription, $langWikiAccessControl, $langWikiAccessControlText, $langWikiCourseMembers, $langWikiGroupMembers, $langWikiOtherUsers, $langWikiOtherUsersText, $langWikiReadPrivilege, $langWikiEditPrivilege, $langWikiCreatePrivilege, $langCancel, $langSave, $langBack, $course_code;
    $title = $title != '' ? $title : '';
    $desc = $desc != '' ? $desc : '';
    if (is_null($acl) && $groupId == 0) {
        $acl = WikiAccessControl::defaultCourseWikiACL();
    } elseif (is_null($acl) && $groupId != 0) {
        $acl = WikiAccessControl::defaultGroupWikiACL();
    }
    // process ACL
    $group_read_checked = $acl['group_read'] == true ? ' checked="checked"' : '';
    $group_edit_checked = $acl['group_edit'] == true ? ' checked="checked"' : '';
    $group_create_checked = $acl['group_create'] == true ? ' checked="checked"' : '';
    $course_read_checked = $acl['course_read'] == true ? ' checked="checked"' : '';
    $course_edit_checked = $acl['course_edit'] == true ? ' checked="checked"' : '';
    $course_create_checked = $acl['course_create'] == true ? ' checked="checked"' : '';
    $other_read_checked = $acl['other_read'] == true ? ' checked="checked"' : '';
    $other_edit_checked = $acl['other_edit'] == true ? ' checked="checked"' : '';
    $other_create_checked = $acl['other_create'] == true ? ' checked="checked"' : '';
    $script = is_null($script) ? $_SERVER['SCRIPT_NAME'] . "?course={$course_code}" : $script;
    $form = action_bar(array(array('title' => $langBack, 'url' => "{$_SERVER['SCRIPT_NAME']}'?course={$course_code}", 'icon' => 'fa-reply', 'level' => 'primary-label')));
    $form .= "<div class='form-wrapper'>\n                <form class='form-horizontal' role='form' method='POST' id='wikiProperties' action='{$script}'>\n                    <fieldset>\n                        <input type='hidden' name='wikiId' value='{$wikiId}'>\n                        <!-- groupId = 0 if course wiki, != 0 if group_wiki  -->\n                        <input type='hidden' name='gid' value='{$groupId}'>                             \n                        <div class='form-group'>\n                            <label for='title' class='col-sm-2 control-label'>{$langWikiTitle}:</label>\n                            <div class='col-sm-10'>\n                                <input name='title' type='text' class='form-control' id='wikiTitle' value='" . q($title) . "' placeholder='{$langWikiTitle}'>\n                            </div>\n                        </div>\n                        <div class='form-group'>\n                            <label for='wikiDesc' class='col-sm-2 control-label'>" . $langWikiDescription . ":</label>\n                            <div class='col-sm-10'>\n                                <textarea class='form-control' id='wikiDesc' name='desc'>" . q($desc) . "</textarea>";
    // atkyritsis
    // hardwiring
    if ($groupId == 0) {
        $form .= "\n                <input type='hidden' name='acl[course_read]' value='on'>\n                <input type='hidden' name='acl[course_edit]' value='on'>\n                <input type='hidden' name='acl[course_create]' value='on'>\n                <input type='hidden' name='acl[other_read]' value='on'>\n                <input type='hidden' name='acl[other_edit]' value='off'>\n                <input type='hidden' name='acl[other_create]' value='off'>";
    } else {
        //default values for group wikis
        $form .= "\n                <input type='hidden' name='acl[group_read]' value='on'>\n                <input type='hidden' name='acl[group_edit]' value='on'>\n                <input type='hidden' name='acl[group_create]' value='on'>\n                <input type='hidden' name='acl[course_read]' value='on'>\n                <input type='hidden' name='acl[course_edit]' value='off'>\n                <input type='hidden' name='acl[course_create]' value='off'>\n                <input type='hidden' name='acl[other_read]' value='off'>\n                <input type='hidden' name='acl[other_edit]' value='off'>\n                <input type='hidden' name='acl[other_create]' value='off'>";
    }
    // hardwiring over
    $form .= "                  </div>\n                            </div>\n                            <div class='form-group'>\n                                <div class='col-sm-10 col-sm-offset-2'>\n                                    <input class='btn btn-primary' type='submit' name='action[exEdit]' value='{$langSave}'>\n                                    <a class='btn btn-default' href='{$_SERVER['SCRIPT_NAME']}?course={$course_code}'>{$langCancel}</a>\n                                </div>\n                            </div>\n                        </fieldset>\n                    </form>\n                </div>";
    return $form;
}
Exemplo n.º 4
0
    $valid_actions = array('list', 'rqSearch', 'exSearch');
}
$_CLEAN = filter_by_key('action', $valid_actions, 'R', false);
$action = isset($_CLEAN['action']) ? $_CLEAN['action'] : 'list';
$wikiId = isset($_REQUEST['wikiId']) ? (int) $_REQUEST['wikiId'] : 0;
$creatorId = claro_get_current_user_id();
// get request variable for wiki edition
if ($action == 'exEdit') {
    $wikiTitle = isset($_POST['title']) ? strip_tags($_POST['title']) : '';
    $wikiDesc = isset($_POST['desc']) ? strip_tags($_POST['desc']) : '';
    if ($wikiDesc == get_lang("Enter the description of your wiki here")) {
        $wikiDesc = '';
    }
    $acl = isset($_POST['acl']) ? $_POST['acl'] : null;
    // initialise access control list
    $wikiACL = WikiAccessControl::emptyWikiACL();
    if (is_array($acl)) {
        foreach ($acl as $key => $value) {
            if ($value == 'on') {
                $wikiACL[$key] = true;
            }
        }
    }
    // force Wiki ACL coherence
    if ($wikiACL['course_read'] == false && $wikiACL['course_edit'] == true) {
        $wikiACL['course_edit'] = false;
    }
    if ($wikiACL['group_read'] == false && $wikiACL['group_edit'] == true) {
        $wikiACL['group_edit'] = false;
    }
    if ($wikiACL['other_read'] == false && $wikiACL['other_edit'] == true) {
Exemplo n.º 5
0
/**
 * Generate html code of Wiki properties edit form
 * @param int wikiId ID of the wiki
 * @param string title wiki tile
 * @param string desc wiki description
 * @param int groupId id of the group the wiki belongs to
 *      (0 for a course wiki)
 * @param array acl wiki access control list
 * @param string script callback script url
 * @return string html code of the wiki properties form
 */
function claro_disp_wiki_properties_form($wikiId = 0, $title = '', $desc = '', $groupId = 0, $acl = null, $script = null)
{
    $title = $title != '' ? $title : get_lang("New Wiki");
    $desc = $desc != '' ? $desc : get_lang("Enter the description of your wiki here");
    if (is_null($acl) && $groupId == 0) {
        $acl = WikiAccessControl::defaultCourseWikiACL();
    } elseif (is_null($acl) && $groupId != 0) {
        $acl = WikiAccessControl::defaultGroupWikiACL();
    }
    // process ACL
    $group_read_checked = $acl['group_read'] == true ? ' checked="checked"' : '';
    $group_edit_checked = $acl['group_edit'] == true ? ' checked="checked"' : '';
    $group_create_checked = $acl['group_create'] == true ? ' checked="checked"' : '';
    $course_read_checked = $acl['course_read'] == true ? ' checked="checked"' : '';
    $course_edit_checked = $acl['course_edit'] == true ? ' checked="checked"' : '';
    $course_create_checked = $acl['course_create'] == true ? ' checked="checked"' : '';
    $other_read_checked = $acl['other_read'] == true ? ' checked="checked"' : '';
    $other_edit_checked = $acl['other_edit'] == true ? ' checked="checked"' : '';
    $other_create_checked = $acl['other_create'] == true ? ' checked="checked"' : '';
    $script = is_null($script) ? Url::Contextualize($_SERVER['PHP_SELF']) : $script;
    $form = '<form method="post" id="wikiProperties" action="' . claro_htmlspecialchars($script) . '">' . "\n" . '<fieldset>' . "\n" . '<legend>' . get_lang("Wiki description") . '</legend>' . "\n" . '<!-- wikiId = 0 if creation, != 0 if edition  -->' . "\n" . '<p class="notice">' . get_lang('You can choose a title and a description for the wiki :') . '</p>' . "\n" . '<input type="hidden" name="wikiId" value="' . $wikiId . '" />' . "\n" . '<!-- groupId = 0 if course wiki, != 0 if group_wiki  -->' . "\n" . '<input type="hidden" name="groupId" value="' . $groupId . '" />' . "\n" . '<dl>' . "\n" . '<dt><label for="wikiTitle">' . get_lang("Title of the wiki") . '</label></dt>' . "\n" . '<dd><input type="text" name="title" id="wikiTitle" size="80" maxlength="254" value="' . claro_htmlspecialchars($title) . '" /></dd>' . "\n" . '<dt><label for="wikiDesc">' . get_lang("Description of the Wiki") . '</label></dt>' . "\n" . '<dd><textarea id="wikiDesc" name="desc" cols="80" rows="10">' . $desc . '</textarea></dd>' . "\n" . '</dl>' . '</fieldset>' . "\n\n" . '<fieldset id="acl">' . "\n" . '<legend>' . get_lang("Access control management") . '</legend>' . "\n" . '<p class="notice">' . get_lang('You can set access rights for users using the following grid :') . '</p>' . "\n" . '<table style="text-align: center; padding: 5px;" id="wikiACL">' . "\n" . '<tr class="matrixAbs">' . "\n" . '<td><!-- empty --></td>' . "\n" . '<td>' . get_lang("Read Pages") . '</td>' . "\n" . '<td>' . get_lang("Edit Pages") . '</td>' . "\n" . '<td>' . get_lang("Create Pages") . '</td>' . "\n" . '</tr>' . "\n" . '<tr>' . "\n" . '<td class="matrixOrd">' . get_lang("Course members") . '</td>' . "\n" . '<td><input type="checkbox" onclick="updateBoxes(\'course\',\'read\');" id="course_read" name="acl[course_read]"' . $course_read_checked . ' /></td>' . "\n" . '<td><input type="checkbox" onclick="updateBoxes(\'course\',\'edit\');" id="course_edit" name="acl[course_edit]"' . $course_edit_checked . ' /></td>' . "\n" . '<td><input type="checkbox" onclick="updateBoxes(\'course\',\'create\');" id="course_create" name="acl[course_create]"' . $course_create_checked . ' /></td>' . "\n" . '</tr>' . "\n";
    if ($groupId != 0) {
        $form .= '<!-- group acl row hidden if groupId == 0, set all to false -->' . "\n" . '<tr>' . "\n" . '<td class="matrixOrd">' . get_lang("Group members") . '</td>' . "\n" . '<td><input type="checkbox" onclick="updateBoxes(\'group\',\'read\');" id="group_read" name="acl[group_read]"' . $group_read_checked . ' /></td>' . "\n" . '<td><input type="checkbox" onclick="updateBoxes(\'group\',\'edit\');" id="group_edit" name="acl[group_edit]"' . $group_edit_checked . ' /></td>' . "\n" . '<td><input type="checkbox" onclick="updateBoxes(\'group\',\'create\');" id="group_create" name="acl[group_create]"' . $group_create_checked . ' /></td>' . "\n" . '</tr>' . "\n";
    }
    $form .= '<tr>' . "\n" . '<td class="matrixOrd">' . get_lang("Others (*)") . '</td>' . "\n" . '<td><input type="checkbox" onclick="updateBoxes(\'other\',\'read\');" id="other_read" name="acl[other_read]"' . $other_read_checked . ' /></td>' . "\n" . '<td><input type="checkbox" onclick="updateBoxes(\'other\',\'edit\');" id="other_edit" name="acl[other_edit]"' . $other_edit_checked . ' /></td>' . "\n" . '<td><input type="checkbox" onclick="updateBoxes(\'other\',\'create\');" id="other_create" name="acl[other_create]"' . $other_create_checked . ' /></td>' . "\n" . '</tr>' . "\n" . '</table>' . "\n" . '<p class="notice">' . get_lang("(*) anonymous users, users who are not members of this course...") . '</p>' . "\n" . '</fieldset>' . "\n\n";
    if ($groupId != 0) {
        $form .= '<input type="hidden" name="gidReq" value="' . $groupId . '" />' . "\n";
    }
    $form .= claro_form_relay_context() . "\n";
    $form .= '<input type="submit" name="action[exEdit]" value="' . get_lang("Ok") . '" />' . "\n" . claro_html_button(claro_htmlspecialchars(Url::Contextualize($_SERVER['PHP_SELF'] . '?action=list')), get_lang("Cancel")) . "\n";
    $form .= '</form>' . "\n";
    return $form;
}
Exemplo n.º 6
0
    /**
     * Export access control list to a string
     * @param array accessControlList access controllist
     * @param boolean echoExport print the exported value
     *      if set to true (default true)
     * @return string string representation of the access control list
     */
    static function exportACL($accessControlList, $echoExport = true) {
        $export = "<pre>\n";
        $prefixList = WikiAccessControl::prefixList();
        $privilegeList = WikiAccessControl::privilegeList();

        foreach ($prefixList as $accessLevel => $prefix) {
            $export .= $accessLevel . ':';

            foreach ($privilegeList as $privilege) {
                $aclKey = $prefix . $privilege;

                $boolValue = ( $accessControlList[$aclKey] == true ) ? 'true' : 'false';
                $export .= $privilege . '(' . $boolValue . ')';
            }

            $export .= "<br />\n";
        }

        $export .= "</pre>\n";

        if ($echoExport == true) {
            echo $export;
        }

        return $export;
    }
Exemplo n.º 7
0
        $is_allowedToRead = $is_allowedToAdmin || claro_is_group_member() && WikiAccessControl::isAllowedToReadPage($accessControlList, 'group') || claro_is_course_member() && WikiAccessControl::isAllowedToReadPage($accessControlList, 'course') || WikiAccessControl::isAllowedToReadPage($accessControlList, 'other');
        $is_allowedToEdit = $is_allowedToRead && ($is_allowedToAdmin || claro_is_group_member() && WikiAccessControl::isAllowedToEditPage($accessControlList, 'group') || claro_is_course_member() && WikiAccessControl::isAllowedToEditPage($accessControlList, 'course') || WikiAccessControl::isAllowedToEditPage($accessControlList, 'other'));
        $is_allowedToCreate = $is_allowedToEdit && ($is_allowedToAdmin || claro_is_group_member() && WikiAccessControl::isAllowedToCreatePage($accessControlList, 'group') || claro_is_course_member() && WikiAccessControl::isAllowedToCreatePage($accessControlList, 'course') || WikiAccessControl::isAllowedToCreatePage($accessControlList, 'other'));
    }
} else {
    // course context
    if (is_array($accessControlList)) {
        // course member
        if (claro_is_course_member() || claro_is_platform_admin()) {
            $is_allowedToRead = $is_allowedToAdmin || WikiAccessControl::isAllowedToReadPage($accessControlList, 'course');
            $is_allowedToEdit = $is_allowedToRead && ($is_allowedToAdmin || WikiAccessControl::isAllowedToEditPage($accessControlList, 'course'));
            $is_allowedToCreate = $is_allowedToEdit && ($is_allowedToAdmin || WikiAccessControl::isAllowedToCreatePage($accessControlList, 'course'));
        } else {
            $is_allowedToRead = $is_allowedToAdmin || WikiAccessControl::isAllowedToReadPage($accessControlList, 'other');
            $is_allowedToEdit = $is_allowedToRead && ($is_allowedToAdmin || WikiAccessControl::isAllowedToEditPage($accessControlList, 'other'));
            $is_allowedToCreate = $is_allowedToEdit && ($is_allowedToAdmin || WikiAccessControl::isAllowedToCreatePage($accessControlList, 'other'));
        }
    }
}
if (!$is_allowedToRead) {
    claro_die(get_lang("You are not allowed to read this page"));
}
// --------------- End of  access rights management ----------------
// filter action
if ($is_allowedToEdit || $is_allowedToCreate) {
    $valid_actions = array('edit', 'preview', 'save', 'show', 'recent', 'diff', 'all', 'history', 'rqSearch', 'exSearch');
} else {
    $valid_actions = array('show', 'recent', 'diff', 'all', 'history', 'rqSearch', 'exSearch');
}
$_CLEAN = filter_by_key('action', $valid_actions, "R", false);
$action = isset($_CLEAN['action']) ? $_CLEAN['action'] : 'show';