public function definition()
 {
     global $CFG;
     $mform = $this->_form;
     // Don't forget the underscore!
     $mform->addElement('hidden', 'community', $this->_customdata['community']);
     $mform->setType('community', PARAM_NOTAGS);
     $mform->addElement('text', 'nome', get_string('labelNome', 'block_webgd_community'));
     $mform->setType('nome', PARAM_TEXT);
     $mform->addRule('nome', get_string('labelValidacaoNome', 'block_webgd_community'), 'required', null, 'client');
     //nรฃo usei o get_string pois nรฃo hรก esse termo no
     $nameButton = get_string('save', 'block_webgd_community');
     if ($this->_customdata['file']) {
         $nameButton = 'Editar';
         $mform->addElement('hidden', 'file', $this->_customdata['file']);
         $webgdCommunityDao = new WebgdCommunityDao();
         $file = $webgdCommunityDao->searchFileById($this->_customdata['file']);
         $mform->setDefault('nome', $file->name);
     } else {
         $mform->addElement('filepicker', 'attachment', get_string('attachment', 'forum'), null, array('accepted_types' => '*'));
         $mform->addRule('attachment', get_string('labelValidacaoArquivo', 'block_webgd_community'), 'required', null, 'client');
     }
     $buttonarray = array();
     $buttonarray[] =& $mform->createElement('submit', 'submitbutton', $nameButton);
     //$buttonarray[] = &$mform->createElement('reset', 'resetbutton', get_string('revert'));
     $buttonarray[] =& $mform->createElement('button', 'cancelar', get_string('cancelar', 'block_webgd_community'), 'onclick=location.href="' . $CFG->wwwroot . '/blocks/webgd_community/view.php?community=' . $this->_customdata['community'] . '"');
     $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
     $mform->closeHeaderBefore('buttonar');
 }
Example #2
0
        redirect("{$CFG->wwwroot}/blocks/webgd_community/view.php?community={$idCommunity}&option=1", get_string('arqNaoEnc', 'block_webgd_community'), 10);
        echo $OUTPUT->footer();
        die;
    } else {
        echo $OUTPUT->heading('<span class="titulo_list">' . '<a href="' . $url . '" >' . $OUTPUT->heading($community->name, 2, 'titulo_comunidade') . '</a></span><br/>');
        echo "<div class='subTitle'>" . get_string('editarArq', 'block_webgd_community') . "</div><br/>";
    }
} else {
    echo $OUTPUT->heading('<span class="titulo_list">' . '<a href="' . $url . '" >' . $OUTPUT->heading($community->name, 2, 'titulo_comunidade') . '</a></span><br/>');
    echo "<div class='subTitle'>" . get_string('cadastrarArq', 'block_webgd_community') . "</div><br/>";
}
$mform = new CadastrarArquivoForm(null, array('community' => $idCommunity, 'file' => $idFile));
if ($data = $mform->get_data()) {
    if ($idFile) {
        $msg = get_string('msgErro', 'block_webgd_community');
        if ($arquivo = $webgdCommunityDao->searchFileById($idFile)) {
            $arquivo->name = $data->nome;
            if ($id = $DB->update_record(TableResouces::$TABLE_PAGE_COMMUNITY_MEDIA, $arquivo)) {
                $msg = get_string('editarArqSuc', 'block_webgd_community');
            }
        }
    } else {
        $name = $mform->get_new_filename('attachment');
        $random = rand();
        $name = $random . '_' . $name;
        $path = "{$CFG->dataroot}/webgd_community/{$name}";
        $msg = get_string('msgErro', 'block_webgd_community');
        if ($mform->save_file('attachment', $path, true)) {
            try {
                $transaction = $DB->start_delegated_transaction();
                $post = new stdClass();
Example #3
0
<?php

require_once dirname(__FILE__) . '/../../../../config.php';
require_once $CFG->dirroot . '/blocks/webgd_community/commons/TableResouces.php';
require_once $CFG->dirroot . '/blocks/webgd_community/lib/class/dao/WebgdCommunityDao.php';
global $USER;
require_login(1);
$PAGE->set_url('/course/index.php');
$PAGE->set_context(context_system::instance());
$PAGE->set_pagelayout('standard');
echo $OUTPUT->header('themeselector');
echo $OUTPUT->heading(get_string('deletarArq', 'block_webgd_community'));
$idFile = optional_param('file', 0, PARAM_INTEGER);
$idCommunity = optional_param('community', 0, PARAM_INTEGER);
$webgdCommunityDao = new WebgdCommunityDao();
$msg = get_string('nenhumArqEnc', 'block_webgd_community');
if ($webgdCommunityDao->searchFileCommunityById($idCommunity, $idFile)) {
    $file = $webgdCommunityDao->searchFileById($idFile);
    if ($webgdCommunityDao->deleteFileByIdUser($file->id, $USER->id, $file->post)) {
        $msg = get_string('deletarArqSuc', 'block_webgd_community');
        unlink($file->path);
    }
}
redirect("{$CFG->wwwroot}/blocks/webgd_community/view.php?community={$idCommunity}", $msg, 10);
echo $OUTPUT->footer();
<?php

require_once dirname(__FILE__) . '/../../../../config.php';
require_once $CFG->dirroot . '/blocks/webgd_community/lib/class/dao/WebgdCommunityDao.php';
require_login(1);
$idFile = optional_param('file', 0, PARAM_INTEGER);
$webgdDao = new WebgdCommunityDao();
$fileBd = $webgdDao->searchFileById($idFile);
if ($fileBd) {
    $file = $fileBd->path;
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename="' . basename($file) . '"');
    header('Content-Length: ' . filesize($file));
    readfile($file);
} else {
    echo 'arquivo nao encontrado';
}