Project

General

Profile

Bug #5265 ยป lp_add_item.php

Yoselyn Castillo, 04/08/2012 08:21

 
1
<?php
2
/* For licensing terms, see /license.txt */
3
/**
4
 * This is a learning path creation and player tool in Chamilo - previously
5
 * learnpath_handler.php
6
 *
7
 * @author Patrick Cool
8
 * @author Denes Nagy
9
 * @author Roan Embrechts, refactoring and code cleaning
10
 * @author Yannick Warnier <ywarnier@beeznest.org> - cleaning and update
11
 * @author Julio Montoya  - Improving the list of templates
12
 * @package chamilo.learnpath
13
 */
14
/**
15
 * INIT SECTION
16
 */
17

    
18
$this_section = SECTION_COURSES;
19

    
20
api_protect_course_script();
21

    
22
include 'learnpath_functions.inc.php';
23
include 'resourcelinker.inc.php';
24

    
25
$language_file = 'learnpath';
26

    
27
$htmlHeadXtra[] = '
28
<script>
29
var temp    = false;
30
var load_default_template = '. ((isset($_POST['submit']) || empty($_SERVER['QUERY_STRING'])) ? 'false' : 'true' ) .';
31

    
32
function FCKeditor_OnComplete( editorInstance ) {
33
    editorInstance.Events.AttachEvent( \'OnSelectionChange\', check_for_title) ;
34
    //document.getElementById(\'frmModel\').innerHTML = "<iframe id=\'frame_template\' name=\'my_frame_template\' height=890px width=220px; frameborder=0 src=\''.api_get_path(WEB_LIBRARY_PATH).'fckeditor/editor/fckdialogframe.html \'>";
35
    loaded = true;
36
}
37

    
38
function check_for_title() {   
39
    if (temp) {  
40
    
41
        // This functions shows that you can interact directly with the editor area
42
        // DOM. In this way you have the freedom to do anything you want with it.
43

    
44
        // Get the editor instance that we want to interact with.
45
        var oEditor = FCKeditorAPI.GetInstance(\'content_lp\') ;
46

    
47
        // Get the Editor Area DOM (Document object).
48
        var oDOM = oEditor.EditorDocument ;
49

    
50
        var iLength ;
51
        var contentText ;
52
        var contentTextArray;
53
        var bestandsnaamNieuw = "";
54
        var bestandsnaamOud = "";
55

    
56
        // The are two diffent ways to get the text (without HTML markups).
57
        // It is browser specific.
58

    
59
        if( document.all )		// If Internet Explorer.
60
        {
61
            contentText = oDOM.body.innerText ;
62
        }
63
        else					// If Gecko.
64
        {
65
            var r = oDOM.createRange() ;
66
            r.selectNodeContents( oDOM.body ) ;
67
            contentText = r.toString() ;
68
        }
69

    
70
        var index=contentText.indexOf("/*<![CDATA");
71
        contentText=contentText.substr(0,index);
72

    
73
        // Compose title if there is none
74
        contentTextArray = contentText.split(\' \') ;
75
        var x=0;
76
        for(x=0; (x<5 && x<contentTextArray.length); x++) {
77
            if(x < 4) {
78
                bestandsnaamNieuw += contentTextArray[x] + \' \';
79
            } else {
80
                bestandsnaamNieuw += contentTextArray[x];
81
            }
82
        }
83
    }
84
    temp=true;
85

    
86
        
87
        
88
}
89

    
90
function InnerDialogLoaded() {
91
    if (document.all) {
92
        // if is iexplorer
93
        var B=new window.frames.content_lp___Frame.FCKToolbarButton(\'Templates\',window.content_lp___Frame.FCKLang.Templates);
94
    } else {
95
        var B=new window.frames[0].FCKToolbarButton(\'Templates\',window.frames[0].FCKLang.Templates);
96
    }
97

    
98
    return 	B.ClickFrame();
99
};'."\n".
100

    
101
$_SESSION['oLP']->get_js_dropdown_array() .
102

    
103
'function load_cbo(id){' ."\n" .
104
  'if (!id) {return false;}'.
105
  'var cbo = document.getElementById(\'previous\');' .
106
  'for(var i = cbo.length - 1; i > 0; i--) {' .
107
    'cbo.options[i] = null;' .
108
  '}' ."\n" .
109
  'var k=0;' .
110
  'for(var i = 1; i <= child_name[id].length; i++){' ."\n" .
111
  '  cbo.options[i] = new Option(child_name[id][i-1], child_value[id][i-1]);' ."\n" .
112
  '  k=i;' ."\n" .
113
  '}' ."\n" .
114
  //'if( typeof cbo != "undefined" ) {'."\n" .
115
  'cbo.options[k].selected = true;'."\n" .
116
   //'}'."\n" .
117
'}
118

    
119
$(function() {
120
    if ($(\'#previous\')) {
121
        if(\'parent is\'+$(\'#idParent\').val()) {
122
            load_cbo($(\'#idParent\').val());
123
        }
124
    }
125
    //Loads LP item tabs
126
    
127
    $("#resource_tab").tabs();
128
    $(\'.lp_resource_element\').click(function() {
129
        window.location.href = $(\'a\', this).attr(\'href\');
130
    });        
131
});
132
</script>';
133

    
134
/* Constants and variables */
135

    
136
$is_allowed_to_edit = api_is_allowed_to_edit(null, true);
137

    
138
$isStudentView  = (int) $_REQUEST['isStudentView'];
139
$learnpath_id   = (int) $_REQUEST['lp_id'];
140
$submit			= $_POST['submit_button'];
141

    
142

    
143
$type = isset($_GET['type']) ? $_GET['type'] : null;
144
$action = isset($_GET['action']) ? $_GET['action'] : null;
145

    
146
// Using the resource linker as a tool for adding resources to the learning path.
147
if ($action == 'add' && $type == 'learnpathitem') {
148
     $htmlHeadXtra[] = "<script language='JavaScript' type='text/javascript'> window.location=\"../resourcelinker/resourcelinker.php?source_id=5&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no\"; </script>";
149
}
150
if ((!$is_allowed_to_edit) || ($isStudentView)) {
151
    error_log('New LP - User not authorized in lp_add_item.php');
152
    header('location:lp_controller.php?action=view&lp_id='.$learnpath_id);
153
    exit;
154
}
155
/* SHOWING THE ADMIN TOOLS */
156

    
157
if (isset($_SESSION['gradebook'])) {
158
    $gradebook = $_SESSION['gradebook'];
159
}
160

    
161
if (!empty($gradebook) && $gradebook == 'view') {
162
    $interbreadcrumb[] = array (
163
            'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
164
            'name' => get_lang('ToolGradebook')
165
        );
166
}
167

    
168
$interbreadcrumb[] = array('url' => 'lp_controller.php?action=list', 'name' => get_lang('LearningPaths'));
169
$interbreadcrumb[] = array('url' => api_get_self()."?action=build&lp_id=$learnpath_id", 'name' => $_SESSION['oLP']->get_name());
170

    
171
switch ($type) {
172
    case 'chapter':
173
        $interbreadcrumb[]= array ('url' => 'lp_controller.php?action=add_item&type=step&lp_id='.$_SESSION['oLP']->get_id(), 'name' => get_lang('NewStep'));
174
        $interbreadcrumb[]= array ('url' => '#', 'name' => get_lang('NewChapter'));
175
        break;
176
    case 'document':
177
        $interbreadcrumb[]= array ('url' => 'lp_controller.php?action=add_item&type=step&lp_id='.$_SESSION['oLP']->get_id(), 'name' => get_lang('NewStep'));
178
        break;
179
    default:
180
        $interbreadcrumb[]= array ('url' => '#', 'name' => get_lang('NewStep'));
181
        break;
182
}
183

    
184
if ($action == 'add_item' && $type == 'document' ) {
185
    $interbreadcrumb[]= array ('url' => '#', 'name' => get_lang('NewDocumentCreated'));
186
}
187

    
188
// Theme calls.
189
$show_learn_path = true;
190
$lp_theme_css = $_SESSION['oLP']->get_theme();
191

    
192
Display::display_header(null, 'Path');
193

    
194
$suredel = trim(get_lang('AreYouSureToDelete'));
195
//@todo move this somewhere else css/fix.css
196
?>
197
<style>
198
    #feedback { font-size: 1.4em; }
199
    #resExercise .ui-selecting { background: #FECA40; }
200
    #resExercise .ui-selected { background: #F39814; color: white; }
201
    #resExercise { list-style-type: none; margin: 0; padding: 0; width: 60%; }
202
    #resExercise li { margin: 3px; padding: 0.4em; font-size: 1.4em; height: 18px; }
203
    
204
    /* Fixes LP toolbar */
205
    #resource_tab li a {
206
        padding: 5px 4px;
207
    }
208
</style>
209
    
210
<script>
211
function stripslashes(str) {
212
    str=str.replace(/\\'/g,'\'');
213
    str=str.replace(/\\"/g,'"');
214
    str=str.replace(/\\\\/g,'\\');
215
    str=str.replace(/\\0/g,'\0');
216
    return str;
217
}
218
function confirmation(name) {
219
    name=stripslashes(name);
220
    if (confirm("<?php echo $suredel; ?> " + name + " ?")) {
221
        return true;
222
    } else {
223
        return false;
224
    }
225
}
226

    
227
$(document).ready(function() {    
228
    $("#hide_bar_template").toggle(
229
        function() { 
230
            $("#lp_sidebar").hide(); 
231
            $(this).css({'background-image' : 'url("../img/hide2.png")'})
232
            $("#doc_form").removeClass("span8"); 
233
            $("#doc_form").addClass("span11");   
234
        },
235
        function() { 
236
            $("#lp_sidebar").show();
237
            $("#doc_form").removeClass("span11"); 
238
            $("#doc_form").addClass("span8"); 
239
            $(this).css('background-image', 'url("../img/hide0.png")'); 
240
        }            
241
    );    
242
});
243
</script>
244
<?php
245

    
246
/* DISPLAY SECTION */
247

    
248
echo $_SESSION['oLP']->build_action_menu();
249

    
250
echo '<div class="row-fluid" style="overflow:hidden">';
251
echo '<div id="lp_sidebar" class="span4">';
252

    
253
echo $_SESSION['oLP']->return_new_tree(null, true); 
254

    
255
// Show the template list.
256
if ($type == 'document' && !isset($_GET['file'])) {    
257
    // Show the template list.        
258
    echo '<div id="frmModel" style="display:block; height:890px;width:100px; position:relative;"></div>';}
259
echo '</div>';
260

    
261
//hide bar div
262
if ($action == 'add_item' && $type == 'document' && !isset($_GET['file'])) {    
263
    echo '<div id="hide_bar_template" ></div>';    
264
}
265

    
266
echo '<div id="doc_form" class="span8">';
267

    
268
if (isset($new_item_id) && is_numeric($new_item_id)) {        
269
    switch ($type) {
270
        case 'chapter':
271
            echo $_SESSION['oLP']->display_manipulate($new_item_id, $_POST['type']);
272
            Display::display_confirmation_message(get_lang('NewChapterCreated'));
273
            break;
274
        case TOOL_LINK:
275
            echo $_SESSION['oLP']->display_manipulate($new_item_id, $type);
276
            Display::display_confirmation_message(get_lang('NewLinksCreated'));
277
            break;
278
        case TOOL_STUDENTPUBLICATION:
279
            echo $_SESSION['oLP']->display_manipulate($new_item_id, $type);
280
            Display::display_confirmation_message(get_lang('NewStudentPublicationCreated'));
281
            break;
282
        case 'module':
283
            echo $_SESSION['oLP']->display_manipulate($new_item_id, $type);
284
            Display::display_confirmation_message(get_lang('NewModuleCreated'));
285
            break;
286
        case TOOL_QUIZ:
287
            echo $_SESSION['oLP']->display_manipulate($new_item_id, $type);
288
            Display::display_confirmation_message(get_lang('NewExerciseCreated'));
289
            break;
290
        case TOOL_DOCUMENT:
291
            Display::display_confirmation_message(get_lang('NewDocumentCreated'));
292
            echo $_SESSION['oLP']->display_item($new_item_id, true);
293
            break;
294
        case TOOL_FORUM:
295
            echo $_SESSION['oLP']->display_manipulate($new_item_id, $type);
296
            Display::display_confirmation_message(get_lang('NewForumCreated'));
297
            break;
298
        case 'thread':
299
            echo $_SESSION['oLP']->display_manipulate($new_item_id, $type);
300
            Display::display_confirmation_message(get_lang('NewThreadCreated'));
301
            break;
302
    }
303
} else {
304
    switch ($type) {
305
        case 'chapter':
306
            echo $_SESSION['oLP']->display_item_form($type, get_lang('EnterDataNewChapter'));
307
            break;
308
        case 'module':
309
            echo $_SESSION['oLP']->display_item_form($type, get_lang('EnterDataNewModule'));
310
            break;
311
        case 'document':
312
            if (isset($_GET['file']) && is_numeric($_GET['file'])) {
313
                echo $_SESSION['oLP']->display_document_form('add', 0, $_GET['file']);
314
            } else {
315
                echo $_SESSION['oLP']->display_document_form('add', 0);
316
            }
317
            break;
318
        case 'hotpotatoes':
319
            echo $_SESSION['oLP']->display_hotpotatoes_form('add', 0, $_GET['file']);
320
            break;
321
        case 'quiz':
322
            echo Display::display_warning_message(get_lang('ExerciseCantBeEditedAfterAddingToTheLP'));
323
            echo $_SESSION['oLP']->display_quiz_form('add', 0, $_GET['file']);
324
            break;
325
        case 'forum':
326
            echo $_SESSION['oLP']->display_forum_form('add', 0, $_GET['forum_id']);
327
            break;
328
        case 'thread':
329
            echo $_SESSION['oLP']->display_thread_form('add', 0, $_GET['thread_id']);
330
            break;
331
        case 'link':
332
            echo $_SESSION['oLP']->display_link_form('add', 0, $_GET['file']);
333
            break;
334
        case 'student_publication':
335
            echo $_SESSION['oLP']->display_student_publication_form('add', 0, $_GET['file']);
336
            break;
337
        case 'step':
338
            $_SESSION['oLP']->display_resources();
339
            break;
340
    }
341
}
342
echo '</div>';
343
echo '</div>';
344

    
345
/* FOOTER */
346
Display::display_footer();
    (1-1/1)