Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        modules
5
 * @package         menu_link
6
 * @author          WebsiteBaker Project
7
 * @copyright       Ryan Djurovich
8
 * @copyright       WebsiteBaker Org. e.V.
9
 * @link            http://websitebaker.org/
10
 * @license         http://www.gnu.org/licenses/gpl.html
11
 * @platform        WebsiteBaker 2.8.3
12
 * @requirements    PHP 5.3.6 and higher
13
 * @version         $Id: modify.php 2 2017-07-02 15:14:29Z Manuela $
14
 * @filesource      $HeadURL: svn://isteam.dynxs.de/wb/2.10.x/branches/main/modules/menu_link/modify.php $
15
 * @lastmodified    $Date: 2017-07-02 17:14:29 +0200 (Sun, 02 Jul 2017) $
16
 *
17
*/
18

    
19
/* -------------------------------------------------------- */
20
// Must include code to stop this file being accessed directly
21
if(defined('WB_PATH') == false) { die('Illegale file access /'.basename(__DIR__).'/'.basename(__FILE__).''); }
22
/* -------------------------------------------------------- */
23

    
24
// check if module language file exists for the language set by the user (e.g. DE, EN)
25
$sAddonsPath = basename(__DIR__);
26
require(WB_PATH .'/modules/'.$sAddonsPath.'/languages/EN.php');
27
if(file_exists(WB_PATH .'/modules/'.$sAddonsPath.'/languages/'.LANGUAGE .'.php')) {
28
    require(WB_PATH .'/modules/'.$sAddonsPath.'/languages/'.LANGUAGE .'.php');
29
}
30

    
31
// get target page_id
32
$table = TABLE_PREFIX.'mod_menu_link';
33
$sql_result = $database->query("SELECT * FROM `$table` WHERE `section_id` = '$section_id'");
34

    
35
$sql_row = $sql_result->fetchRow( MYSQLI_ASSOC );
36
$target_page_id = $sql_row['target_page_id'];
37
$r_type = $sql_row['redirect_type'];
38
$extern = $sql_row['extern'];
39
$anchor = $sql_row['anchor'];
40
$sel = ' selected="selected"';
41

    
42
// Get list of all visible pages and build a page-tree
43

    
44
// this function will fetch the page_tree, recursive
45
if(!function_exists('menulink_make_tree')) {
46
function menulink_make_tree($parent, $link_pid, $tree) {
47
    global $database, $admin, $menulink_titles;
48
    $table_p = TABLE_PREFIX."pages";
49
    // get list of page-trails, recursive
50
    if($query_page = $database->query("SELECT * FROM `$table_p` WHERE `parent`=$parent ORDER BY `position`")) {
51
        while($page = $query_page->fetchRow(MYSQLI_ASSOC)) {
52
            if($admin->page_is_visible($page) ) {
53
                $pids = explode(',', $page['page_trail']);
54
                $entry = '';
55
                foreach($pids as $pid)
56
                    $entry .= $menulink_titles[$pid].' / ';
57
                $tree[$page['page_id']] = rtrim($entry, '/ ');
58
                $tree = menulink_make_tree($page['page_id'], $link_pid, $tree);
59
            }
60
        }
61
    }
62
    return($tree);
63
}
64
}
65

    
66
// get list of all page_ids and page_titles
67
global $menulink_titles;
68
$menulink_titles = array();
69
$table_p = TABLE_PREFIX."pages";
70
if($query_page = $database->query("SELECT `page_id`,`menu_title` FROM `$table_p`")) {
71
    while($page = $query_page->fetchRow(MYSQLI_ASSOC))
72
        $menulink_titles[$page['page_id']] = $page['menu_title'];
73
}
74
// now get the tree
75
$links = array();
76
$links = menulink_make_tree(0, $page_id, $links);
77

    
78
// Get list of targets (id=... or <a name ...>) from pages in $links
79
$targets = array();
80
$table_mw = TABLE_PREFIX."mod_wysiwyg";
81
$table_s = TABLE_PREFIX."sections";
82
foreach($links as $pid=>$l) {
83
    if($query_section = $database->query("SELECT `section_id`, `module` FROM `$table_s` WHERE `page_id` = '$pid' ORDER BY position")) {
84
        while($aMenuLink = $query_section->fetchRow(MYSQLI_ASSOC)) {
85
            // get section-anchor
86
            if(defined('SEC_ANCHOR') && SEC_ANCHOR!='') {
87
                $targets[$pid][] = SEC_ANCHOR.$aMenuLink['section_id'];
88
            } else {
89
                $targets[$pid] = array();
90
            }
91
            if($aMenuLink['module'] == 'wysiwyg') {
92
                if($query_page = $database->query("SELECT `content` FROM $table_mw WHERE `section_id` = '{$aMenuLink['section_id']}' ")) {
93
                    $page = $query_page->fetchRow(MYSQLI_ASSOC);
94
                    if(preg_match_all('/<(?:a[^>]+name|[^>]+id)\s*=\s*"([^"]+)"/i',$page['content'], $match)) {
95
                        foreach($match[1] AS $t) {
96
                            $targets[$pid][$t] = $t;
97
                        }
98
                    }
99
                }
100
            }
101
        }
102
    }
103
}
104
// get target-window for actual page
105
$table = TABLE_PREFIX."pages";
106
$query_page = $database->query("SELECT target FROM $table WHERE page_id = '$page_id'");
107
$page = $query_page->fetchRow();
108
$target = $page['target'];
109

    
110

    
111
// script for target-select-box
112
?>
113
<script language="JavaScript" type="text/javascript">
114
/*<![CDATA[*/
115
    function populate() {
116
        o=document.getElementById('menu_link');
117
        d=document.getElementById('page_target');
118
        e=document.getElementById('extern');
119
        if(!d){return;}
120
        var mitems=new Array();
121
        mitems['0']=[' ','0'];
122
        mitems['-1']=[' ','0'];
123
        <?php
124
        foreach($links AS $pid=>$link) {
125
            $str="mitems['$pid']=[";
126
            $str.="' ',";
127
            $str.="'0',";
128
            if(is_array($targets) && is_array($targets[$pid])) {
129
                foreach($targets[$pid] AS $value) {
130
                    $str.="'#$value',";
131
                    $str.="'$value',";
132
                }
133
                $str=rtrim($str, ',');
134
                $str.="];\n";
135
            }
136
            echo $str;
137
        }
138
        ?>
139
        d.options.length=0;
140
        cur=mitems[o.options[o.selectedIndex].value];
141
        if(!cur){return;}
142
        d.options.length=cur.length/2;
143
        j=0;
144
        for(var i=0;i<cur.length;i=i+2)
145
        {
146
            d.options[j].text=cur[i];
147
            d.options[j++].value=cur[i+1];
148
        }
149

    
150
        if(o.value=='-1') {
151
            e.disabled = false;
152
        } else {
153
            e.disabled = true;
154
        }
155
    }
156

    
157
/*]]>*/
158
</script>
159
<form name="menulink" action="<?php echo WB_URL ?>/modules/menu_link/save.php" method="post">
160
<input type="hidden" name="page_id" value="<?php echo $page_id ?>" />
161
<input type="hidden" name="section_id" value="<?php echo $section_id ?>" />
162
<?php echo $admin->getFTAN(); ?>
163
<table cellpadding="0" cellspacing="0" border="0" width="100%">
164
<tr>
165
    <td>
166
        <?php echo $TEXT['LINK'].':' ?>
167
    </td>
168
    <td>
169
        <select name="menu_link" id="menu_link" onchange="populate()" style="width:250px;" >
170
            <option value="0"<?php echo $target_page_id=='0'?$sel:''?>><?php echo $TEXT['PLEASE_SELECT']; ?></option>
171
            <option value="-1"<?php echo $target_page_id=='-1'?$sel:''?>><?php echo $MOD_MENU_LINK['EXTERNAL_LINK']; ?></option>
172
            <?php foreach($links AS $pid=>$link) {
173
                if ($pid == $page_id)  // Display current page with selection disabled
174
                    echo "<option value=\"$pid\" disabled=\"disabled\">$link *</option>\n";
175
                else
176
                    echo "<option value=\"$pid\" ".($target_page_id==$pid?$sel:'').">$link</option>\n";
177
            } ?>
178
        </select>
179
        &nbsp;
180
        <input type="text" name="extern" id="extern" value="<?php echo $extern; ?>" style="width:250px;" <?php if($target_page_id!='-1') echo 'disabled="disabled"'; ?> />
181
    </td>
182
</tr>
183
<tr>
184
    <td>
185
        <?php echo $TEXT['ANCHOR'].':' ?>
186
    </td>
187
    <td>
188
        <select name="page_target" id="page_target" onfocus="populate()" style="width:250px;" >
189
            <option value="<?php echo $anchor ?>" selected="selected"><?php echo $anchor=='0'?' ':'#'.$anchor ?></option>
190
        </select>
191
    </td>
192
</tr>
193
<tr>
194
    <td>
195
        <?php echo $TEXT['TARGET'].':' ?>
196
    </td>
197
    <td>
198
        <select name="target" style="width:250px;" >
199
            <option value="_blank"<?php if($target=='_blank') echo ' selected="selected"'; ?>><?php echo $TEXT['NEW_WINDOW'] ?></option>
200
            <option value="_self"<?php if($target=='_self') echo ' selected="selected"'; ?>><?php echo $TEXT['SAME_WINDOW'] ?></option>
201
            <option value="_top"<?php if($target=='_top') echo ' selected="selected"'; ?>><?php echo $TEXT['TOP_FRAME'] ?></option>
202
        </select>
203
    </td>
204
</tr>
205
<tr>
206
    <td>
207
        <?php echo $MOD_MENU_LINK['R_TYPE'].':' ?>
208
    </td>
209
    <td>
210
        <select name="r_type" style="width:250px;" >
211
            <option value="301"<?php if($r_type=='301') echo ' selected="selected"'; ?>>301</option>
212
            <option value="302"<?php if($r_type=='302') echo ' selected="selected"'; ?>>302</option>
213
        </select>
214
    </td>
215
</tr>
216
</table>
217

    
218
<br />
219

    
220
<table cellpadding="0" cellspacing="0" border="0" width="100%">
221
<tr>
222
    <td align="left">
223
        <input type="submit" value="<?php echo $TEXT['SAVE'] ?>" style="width: 100px; margin-top: 5px;" />
224
    </td>
225
    <td align="right">
226
        <input type="button" value="<?php echo $TEXT['CANCEL'] ?>" onclick="javascript: window.location = 'index.php';" style="width: 100px; margin-top: 5px;" />
227
    </td>
228
</tr>
229
</table>
230

    
231
</form>
(8-8/11)