We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28245
    • 20 Posts
    now all pages shows in link list in tinymce when you create new links.
    I only whant pages thats belong to your doc.grope to show in link list.
    I think it should be some more code below? butt what?

    
    #more code above
    
    $tblsc = $dbase.".".$table_prefix."site_content";
        $tbldg = $dbase.".".$table_prefix."document_groups";
    
        // modify field names to use sc. table reference
        $fields = 'sc.'.implode(',sc.',preg_replace("/^\s/i","",explode(',',$fields)));
        $sort = 'sc.'.implode(',sc.',preg_replace("/^\s/i","",explode(',',$sort)));
    
    	// Connecting, selecting database
    	$link = mysql_connect($database_server, $database_user, $database_password) or die('Could not connect: ' . mysql_error());
    	$dbase = str_replace('`', '', $dbase);
    	mysql_select_db($dbase) or die('Could not select database');
    
        $sql = "SELECT DISTINCT $fields FROM $tblsc sc
          LEFT JOIN $tbldg dg on dg.document = sc.id
          WHERE sc.published=1 AND sc.deleted=0
          ORDER BY $sort $dir;";
    
    #More code below
    
    
    



    can some one help me smiley
      • 18397
      • 3,250 Posts
      Its the SQL statement. It is not excluding the documents you don’t have permission to view.

      Maybe something like this? (not sure if $modx is available in that particular script)

      			// get document groups for current user
      			if ($docgrp= $modx->getUserDocGroups())
      			$docgrp= implode(",", $docgrp);
      			$access= ($modx->isFrontend() ? "sc.privateweb=0" : "1='" . $_SESSION['mgrRole'] . "' OR sc.privatemgr=0") .
      			(!$docgrp ? "" : " OR dg.document_group IN ($docgrp)");
      
      	
      		$sql= "SELECT DISTINCT $fields FROM $tblsc sc
      		LEFT JOIN $tbldg dg on dg.document = sc.id
      		WHERE sc.published=1 AND sc.deleted=1
      		AND ($access) GROUP BY sc.id ORDER BY $sort $dir;";
      
        • 28245
        • 20 Posts
        I guess $modx isn’t available in that script because it didn’t work, it printed nothing at linklist line now sad
        is it possible to make $modx available in that script "modxLinkList.php" and if it’s possible how should the code look like?

        I really need help on this one undecided

        //Spunk
          • 10487 MODX Staff
          • 1,535 Posts
          Well, you can make $modx available - I did something similar in my DocManager module for the Ajax elements. The code I used is (works for MODx 0.9.6 RCs - can’t remember when protect.inc.php was introduced so may work with MODx 0.9.5):
           require_once '../../../manager/includes/protect.inc.php'; 
           include_once ("../../../manager/includes/config.inc.php");
           include_once(MODX_BASE_PATH."manager/includes/document.parser.class.inc.php");
           $modx = new DocumentParser;
          

          Remove the current include_once statement (for config.inc.php) at the top of the file and then paste the above code in it’s place and you should be good to go wink Let me know if you have any problems.

          Hope that helps,
          Garry
            Garry Nutting
            Senior Developer
            MODX, LLC

            Email: [email protected]
            Twitter: @garryn
            Web: modx.com
            • 28245
            • 20 Posts
            hmm... no. it didn’t work. undecided

            the file "protect.inc.php" wasn’t available in 0.9.5 butt I downloaded 0.9.6 for the "protect.inc.php" or is it more files needed.

            Here is the code of the file.
            <?php
            require_once '../../../manager/includes/protect.inc.php';
            include_once ("../../../manager/includes/config.inc.php");
            include_once(MODX_BASE_PATH."manager/includes/document.parser.class.inc.php");
            $modx = new DocumentParser;
            #include_once "../../../manager/includes/config.inc.php";
            
            
            $allpages = getAllPages();
            foreach($allpages as $page){
                $caption = ($page['pagetitle'])?htmlspecialchars($page['pagetitle'],ENT_QUOTES):htmlspecialchars($page['menutitle'],ENT_QUOTES);
            	$list .=($list!='')?",\n":"\n";
            	$list.= "[\"".$caption." (".$page['id'].")"."\", \"[\"+\"~".$page['id']."~\"+\"]\"]";
            }   
            
            $output = "var tinyMCELinkList = new Array(\n". $list .");";
            
            echo $output;
            
            
            
             function getAllPages($id=0, $sort='menuindex', $dir='ASC', $fields='pagetitle, id, menutitle, editedby') {
                global $database_type;
                global $database_server;
                global $database_user;
                global $database_password;    
            	global $dbase;
            	global $table_prefix;
            
            
            
                $tblsc = $dbase.".".$table_prefix."site_content";
                $tbldg = $dbase.".".$table_prefix."document_groups";
            
                // modify field names to use sc. table reference
                $fields = 'sc.'.implode(',sc.',preg_replace("/^\s/i","",explode(',',$fields)));
                $sort = 'sc.'.implode(',sc.',preg_replace("/^\s/i","",explode(',',$sort)));
            
            	// Connecting, selecting database
            	$link = mysql_connect($database_server, $database_user, $database_password) or die('Could not connect: ' . mysql_error());
            	$dbase = str_replace('`', '', $dbase);
            	mysql_select_db($dbase) or die('Could not select database');
            
             // get document groups for current user
            			if ($docgrp= $modx->getUserDocGroups())
            			$docgrp= implode(",", $docgrp);
            			$access= ($modx->isFrontend() ? "sc.privateweb=0" : "1='" . $_SESSION['mgrRole'] . "' OR sc.privatemgr=0") .
            			(!$docgrp ? "" : " OR dg.document_group IN ($docgrp)");
            
            	
            		$sql= "SELECT DISTINCT $fields FROM $tblsc sc
            		LEFT JOIN $tbldg dg on dg.document = sc.id
            		WHERE sc.published=1 AND sc.deleted=1
            		AND ($access) GROUP BY sc.id ORDER BY $sort $dir;";
            
            
            /*
                $sql = "SELECT DISTINCT $fields FROM $tblsc sc
                  LEFT JOIN $tbldg dg on dg.document = sc.id
                  WHERE sc.published=1 AND sc.deleted=0
                  ORDER BY $sort $dir;";
             */
                $result = mysql_query($sql) or die('Query failed: ' . mysql_error());
                $resourceArray = array();
                for($i=0;$i<@mysql_num_rows($result);$i++)  {
                  array_push($resourceArray,mysql_fetch_assoc($result));
                }
            	// Free resultset
            	mysql_free_result($result);
            	
            	// Closing connection
            	mysql_close($link);
            	
            	sort($resourceArray);
            
                return $resourceArray;
            }
            ?>
              • 10487 MODX Staff
              • 1,535 Posts
              Okay, as long as it’s not failing on any of the require_once statements then I think the only thing that is needed is a ’global $modx’ statement at the top of the getAllPages function:
              function getAllPages($id=0, $sort='menuindex', $dir='ASC', $fields='pagetitle, id, menutitle, editedby') {
                  global $modx;
                  global $database_type;
                  global $database_server;
                  global $database_user;
                  global $database_password;    
                  global $dbase;
                  global $table_prefix;
              
              ...
              

              Hope that helps,
              Garry
                Garry Nutting
                Senior Developer
                MODX, LLC

                Email: [email protected]
                Twitter: @garryn
                Web: modx.com
                • 28245
                • 20 Posts
                still same problem. undecided
                if i chance this code
                  $sql = "SELECT DISTINCT $fields FROM $tblsc sc
                      LEFT JOIN $tbldg dg on dg.document = sc.id
                      WHERE sc.published=1 AND sc.deleted=0
                      ORDER BY $sort $dir;";
                

                to this it show only pages edited by user 2
                  $sql = "SELECT DISTINCT $fields FROM $tblsc sc
                      LEFT JOIN $tbldg dg on dg.document = sc.id
                      WHERE sc.published=1 AND sc.deleted=0 AND sc.editedby = 2
                      ORDER BY $sort $dir;";
                


                and if i do like this
                 
                $usid = $modx->getLoginUserID( );
                
                 $sql = "SELECT DISTINCT $fields FROM $tblsc sc
                      LEFT JOIN $tbldg dg on dg.document = sc.id
                      WHERE sc.published=1 AND sc.deleted=0 AND sc.editedby = $usid
                      ORDER BY $sort $dir;";
                


                no links in the list

                this is just an example. so i guess $modx is not working

                //Spunk
                  • 10487 MODX Staff
                  • 1,535 Posts
                  Hmmm, the problem is that the $_SESSION variables aren’t available for getLoginUserID() to work properly - $modx is working, but not the $_SESSION variables. I’ve tried a few things and seem unable to get the current session available, I’ll keep trying ...
                    Garry Nutting
                    Senior Developer
                    MODX, LLC

                    Email: [email protected]
                    Twitter: @garryn
                    Web: modx.com
                    • 22303 MODX Staff
                    • 10,725 Posts
                    With 0.9.6, if you are not in a request indicated as web or mgr, you need to specify which you want back (i.e. $modx->getLoginUserID(’mgr’); or $modx->getLoginUserID(’web’); ) Also, you may need to call startCMSSession() at some point to handle configurations where session.auto_start is not set to 1.

                    Quote from: garryn at May 06, 2007, 09:08 AM

                    Hmmm, the problem is that the $_SESSION variables aren’t available for getLoginUserID() to work properly - $modx is working, but not the $_SESSION variables. I’ve tried a few things and seem unable to get the current session available, I’ll keep trying ...