Location: PHPKode > projects > DOOR - Digital Open Object Repository > door/admin/popupList.php
<?php
    // include libraries
    require_once("../setup.php");
	if($logged_in != 1) { //not logged
		error_catcher(1);
		exit;
	} else { //inizio 1° else
        if (isset($_POST['submitted'])) {       // NOT SUBMITTED
            // check input data
            if (!isset($_SESSION["action"]) OR
                !isset($_SESSION["form"])) {
                @ob_clean();
                error_catcher(44);
                exit;
            }
            // choices
            $choices = isset($_POST["choices"]) ? $_POST["choices"] : array();
            // strings
            $parameters_labels = "";
            $parameters_values = "";
            switch ($_SESSION["action"]) {
                case 'teaching_disciplines':
                    $parameters_labels = "";
                    if (count($choices) > 0) {
                        foreach ($choices as $choice) {
                            $parameters_labels .= get_string("teaching_disciplines", $choice) . ", ";    
                        }
                        $parameters_labels = substr($parameters_labels, 0, (strlen($parameters_labels) - 2));
                    }
                default:
                    $parameters_values = implode(", ", $choices);
                    break;
            }
?>
        <html>
            <head>
                <script language="JavaScript">
                    function htmlescape(str){ 
                        str = str.replace(/&amp;/g, '&'); 
                        str = str.replace(/&lt;/g, '<'); 
                        str = str.replace(/&gt;/g, '>'); 
                        str = str.replace(/&quot;/g, '\"');
                        str = str.replace(/&#039;/g, '\'');
                        return str; 
                    }
                    function html_entity_decode(string) { 
                        var ret, tarea = document.createElement('textarea');
                        tarea.innerHTML = string;
                        ret = tarea.value;
                        return ret;
                    }
                    function setValues(field,string,form) {
                        if (field == 'teaching_disciplines_labels') {
                            string = html_entity_decode(string);        
                        }                        
                        if (window.opener && !window.opener.closed){
                            if(form==0){
                                window.opener.document.search_menu_form.elements[field].value = string;    
                            }else{
                                window.opener.document.theForm.elements[field].value = string;    
                            }
                        }
                    }
                    setValues('<?php echo $_SESSION["action"]; ?>', '<?php echo $parameters_values; ?>', '<?php echo $_SESSION["form"]; ?>');                
            <?php
                    if ($_SESSION["action"] == 'teaching_disciplines') {
            ?>
                    setValues('<?php echo $_SESSION["action"] . "_labels"; ?>', '<?php echo $parameters_labels; ?>', '<?php echo $_SESSION["form"]; ?>');
            <?php
                    }
            ?>    
                </script>   
            </head>
            <body onload="window.close();">
            </body>
        </html>
<?php
        } else {
?>
        <html>
            <head>
                <title>
<?php 
                get_string('parameters', 'ParametersPopupTitle');
?>
                </title> 
                <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
				<script language="JavaScript">
					
                    function selectCB(id, father) {
                        var el = document.getElementById(id); 
                        var father = document.getElementById(father);
                        if (father && el.checked) {
                            father.checked = true ;
                            father.onclick()    
                        }  
                    }
					
					
					function selectAll(path){
						this.location.href=path;
					}
                </script> 
				<link href="../css/style.css" rel="stylesheet" type="text/css">
            </head> 
<?php
                // input data
                $query_string_array = array($_SERVER["QUERY_STRING"]);
                $input_data = array();
                if (strpos($_SERVER["QUERY_STRING"], "&")) {
                    $query_string_array = explode("&", $_SERVER["QUERY_STRING"]);
                }
                if (is_array($query_string_array) and count($query_string_array) > 0) {
                    foreach ($query_string_array as $pair) {
                        if (strpos($pair, "=")) {
                            $tmp = explode("=", $pair);
                            $input_data[$tmp[0]] = urldecode($tmp[1]); 
                        }    
                    }    
                }
                
                $action = "";
                $vals = "";
                $form = 1;
                // action
                if (array_key_exists("action", $input_data)) {
                    $action = $input_data["action"];
                }
                // form
                if (array_key_exists("form", $input_data)) {
                    $form = $input_data["form"];
                }
                // vals
                if (array_key_exists("vals", $input_data)) {
                    $vals = $input_data["vals"];
                    if (!seems_utf8($vals)) {
                        $vals = utf8_encode($vals);
                    }
                }
                			    
                // extract list of parameters (depending from action value)
                switch ($action) {
                    case 'catalog_reference':
                        $values = array();
                        $title_string = "";
                        break;
                    case 'type_of_resource':
                        $values = get_list("resource_type");
                        $title_string = get_string('parameters', 'ParametersPopupTypesOfResources');
                        break;
                    case 'useIn':
                        $values = get_list("use_in");
                        $title_string = get_string('parameters', 'ParametersPopupUseContexts');
                        break;
                    case 'useBy':
                        $values = get_list("use_by");
                        $title_string = get_string('parameters', 'ParametersPopupTargetUsers');
                        break;
                    case 'language':
                        $values = get_list("language");
                        $title_string = get_string('parameters', 'ParametersPopupLanguage');
                        break;
                    case 'keywords':
                        $values = get_list("keyword");
                        $title_string = get_string('parameters', 'ParametersPopupKeywords');
                        break;
                    case 'teaching_disciplines':
                        $values = get_teaching_disciplines_list();
                        $title_string = get_string('parameters', 'ParametersPopupTeachingDisciplines');
                        break;
                }
        
                // get checked values
                $checked_values = array();
			    if ($vals != "all" AND $vals != "none") {
				    $checked_values = parsestring($vals, ',');
                }
                $_SESSION["action"] = $action;
                $_SESSION["form"] = $form;
?>
			<body>
<?php 
			if (count($values) > 0) {
?>
				<div style="margin:5px">
					<form name="valuesForm" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
						<input type="hidden" name="submitted" value="true">
						<table border="0" cellspacing="0" cellpadding="3" align="center">
							<tr bgcolor="#ffffff" class="txt"> 
								<td colspan="2"><strong><?php echo $title_string ?></strong></td>
							</tr>
							<tr bgcolor="#ffffff" class="txt">
								<td colspan="2">
									<input class="button" name="select_all" type="button" value="<?php echo get_string('parameters', 'ParametersPopupSelectAllButton'); ?>" onClick="javascript:selectAll('popupList.php?action=<?php echo $action; ?>&vals=all&form=<?php echo $form; ?>')">
									<input class="button" name="clear_all" type="button" value="<?php echo get_string('parameters', 'ParametersPopupTitleClearAllButton'); ?>" onClick="javascript:selectAll('popupList.php?action=<?php echo $action; ?>&vals=none&form=<?php echo $form; ?>')">
								</td>
							</tr>
							<?php 	foreach($values as $field => $value){?>
										<tr bgcolor="#dddddd" class="txt"> 
										<?php 	if ($action=='catalog_reference') { ?>
													<td width="10">&nbsp;</td>
													<td><a href="javascript:pick('<?php echo $action; ?>','<?php echo $value; ?>','<?php echo $form;?>')"><?php //echo $value; ?></a>
										<?php	} else {
                                                    if ($action == 'teaching_disciplines') {
                                                        $val = htmlentities($value["name"], ENT_QUOTES, "UTF-8");
                                                        $cval = $value["name"];
                                                        $label = get_string('teaching_disciplines', $value["name"]);
                                                        $td_class = sprintf("class=\"td_level%u\"", count(explode(".", $value["name"])));
                                                        $onclick_event = sprintf("onclick=\"javascript:selectCB('%s', '%s');\"", htmlentities($field, ENT_QUOTES, "UTF-8"), htmlentities($value["father"], ENT_QUOTES, "UTF-8"));   
                                                    } else {
                                                        $val = htmlentities($value, ENT_QUOTES, "UTF-8");
                                                        $cval = $value;
                                                        $label = $val;
                                                        $td_class = "";
                                                        $onclick_event = "";
                                                    }
                                                    /*echo "<pre>";
                                                    var_dump($cval);
                                                    echo "</pre>";
                                                    echo "<pre>";
                                                    var_dump($checked_values);
                                                    echo "</pre>";
                                                    exit;*/
													// select element if case
													$checked = "";
													if ((is_array($checked_values) AND in_array(strtolower($cval), $checked_values)) OR $vals == "all") {
                                                        $checked = "checked";
                                                    }
                                        ?>
                                                    <td colspan="2" <?php echo $td_class; ?>>
                                                        <input id="<?php echo $field; ?>" name="choices[]" <?php echo $onclick_event; ?> type="checkbox" <?php echo $checked; ?> value="<?php echo $val; ?>"><?php echo $label; ?>
                                                    </td>
                                        <?php
										        } //endelse
                                        ?>
                                        </tr>
									<?php }//end foreach ?>
							<tr bgcolor="#ffffff">
								<td colspan="2"><input class="button" type="submit" name="select" value="<?php echo get_string('parameters', 'ParametersPopupTitleSubmitButton'); ?>"></td>
							</tr>
						</table>
					</form>
<?php 		} else { ?>
				  <table width="100%" border="0" cellspacing="0" cellpadding="0">
					<tr>
					  <td align="center"><p>&nbsp;</p>
					<table border="0" cellspacing="1" cellpadding="1">
						  <tr bgcolor="#ffffff" class="txt"> 
							<td class="txt"><strong><?php echo $title_string; ?></strong></td>
						  </tr>
						  <tr bgcolor="#ffffff" class="txt"> 
							<td class="txt">
							<?php echo get_string('parameters', 'ParametersPopupNoItemsMessage'); ?>
							<br><a href="#" onClick="window.close()"><?php echo get_string('parameters', 'ParametersPopupNoItemsCloseWindowLink'); ?></a> 
							</td>
						  </tr>
						</table>
					  </td>
					</tr>
				  </table>

<?php 
			}
        }
    }
?>
</div>
</body>
</html>
Return current item: DOOR - Digital Open Object Repository