<div dir="ltr">Adam,<div style>     I made some changes in function. and it seems working nicly</div><div style><br></div><div style><ol style="margin:0px;padding:0px 0px 0px 48px;color:rgb(172,172,172);font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono',monospace,serif;font-size:12px;line-height:21px;background-color:rgb(248,248,248)">

<li class="" style><div class="" style="padding:0px 5px;vertical-align:top;color:rgb(0,0,0);border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);background-color:rgb(255,255,255);line-height:21px">

<span class="" style="font-weight:bold">function</span> getReportingUsers<span class="" style="color:rgb(0,153,0)">(</span><span class="" style="color:rgb(0,0,136)">$userId</span><span class="" style="color:rgb(51,153,51)">,</span> <span class="" style="color:rgb(51,153,51)">&</span><span class="" style="color:rgb(0,0,136)">$acc</span><span class="" style="color:rgb(0,153,0)">)</span> <span class="" style="color:rgb(0,153,0)">{</span></div>

</li><li class="" style><div class="" style="padding:0px 5px;vertical-align:top;color:rgb(0,0,0);border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);background-color:rgb(255,255,255);line-height:21px">

    <span class="" style="font-weight:bold">global</span> <span class="" style="color:rgb(0,0,136)">$log</span><span class="" style="color:rgb(51,153,51)">;</span></div></li><li class="" style><div class="" style="padding:0px 5px;vertical-align:top;color:rgb(0,0,0);border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);background-color:rgb(255,255,255);line-height:21px">

    <span class="" style="color:rgb(0,0,136)">$log</span><span class="" style="color:rgb(51,153,51)">-></span><span class="" style="color:rgb(0,64,0)">debug</span><span class="" style="color:rgb(0,153,0)">(</span><span class="" style="color:rgb(0,0,255)">"Entering getReportingUsers("</span> <span class="" style="color:rgb(51,153,51)">.</span> <span class="" style="color:rgb(0,0,136)">$userId</span> <span class="" style="color:rgb(51,153,51)">.</span> <span class="" style="color:rgb(0,0,255)">") method ..."</span><span class="" style="color:rgb(0,153,0)">)</span><span class="" style="color:rgb(51,153,51)">;</span></div>

</li><li class="" style><div class="" style="padding:0px 5px;vertical-align:top;color:rgb(0,0,0);border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);background-color:rgb(255,255,255);line-height:21px">

    <span class="" style="font-weight:bold">global</span> <span class="" style="color:rgb(0,0,136)">$adb</span><span class="" style="color:rgb(51,153,51)">;</span></div></li><li class="" style><div class="" style="padding:0px 5px;vertical-align:top;color:rgb(0,0,0);border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);background-color:rgb(255,255,255);line-height:21px">

    <span class="" style="color:rgb(0,0,136)">$log</span><span class="" style="color:rgb(51,153,51)">-></span><span class="" style="color:rgb(0,64,0)">debug</span><span class="" style="color:rgb(0,153,0)">(</span><span class="" style="color:rgb(0,0,136)">$acc</span><span class="" style="color:rgb(0,153,0)">)</span><span class="" style="color:rgb(51,153,51)">;</span></div>

</li><li class="" style><div class="" style="padding:0px 5px;vertical-align:top;color:rgb(0,0,0);border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);background-color:rgb(255,255,255);line-height:21px">

    <span class="" style="color:rgb(0,0,136)">$sql</span> <span class="" style="color:rgb(51,153,51)">=</span> <span class="" style="color:rgb(0,0,255)">"select id from vtiger_users where reports_to_id = ?"</span><span class="" style="color:rgb(51,153,51)">;</span></div>

</li><li class="" style><div class="" style="padding:0px 5px;vertical-align:top;color:rgb(0,0,0);border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);background-color:rgb(255,255,255);line-height:21px">

    <span class="" style="color:rgb(0,0,136)">$result</span> <span class="" style="color:rgb(51,153,51)">=</span> <span class="" style="color:rgb(0,0,136)">$adb</span><span class="" style="color:rgb(51,153,51)">-></span><span class="" style="color:rgb(0,64,0)">pquery</span><span class="" style="color:rgb(0,153,0)">(</span><span class="" style="color:rgb(0,0,136)">$sql</span><span class="" style="color:rgb(51,153,51)">,</span> <span class="" style="color:rgb(153,0,0)">array</span><span class="" style="color:rgb(0,153,0)">(</span><span class="" style="color:rgb(0,0,136)">$userId</span><span class="" style="color:rgb(0,153,0)">)</span><span class="" style="color:rgb(0,153,0)">)</span><span class="" style="color:rgb(51,153,51)">;</span></div>

</li><li class="" style><div class="" style="padding:0px 5px;vertical-align:top;color:rgb(0,0,0);border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);background-color:rgb(255,255,255);line-height:21px">

    <span class="" style="color:rgb(0,0,136)">$num_rows</span> <span class="" style="color:rgb(51,153,51)">=</span> <span class="" style="color:rgb(0,0,136)">$adb</span><span class="" style="color:rgb(51,153,51)">-></span><span class="" style="color:rgb(0,64,0)">num_rows</span><span class="" style="color:rgb(0,153,0)">(</span><span class="" style="color:rgb(0,0,136)">$result</span><span class="" style="color:rgb(0,153,0)">)</span><span class="" style="color:rgb(51,153,51)">;</span></div>

</li><li class="" style><div class="" style="padding:0px 5px;vertical-align:top;color:rgb(0,0,0);border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);background-color:rgb(255,255,255);line-height:21px">

    <span class="" style="color:rgb(177,177,0)">if</span> <span class="" style="color:rgb(0,153,0)">(</span><span class="" style="color:rgb(0,0,136)">$num_rows</span> <span class="" style="color:rgb(51,153,51)"><</span> <span class="" style="color:rgb(204,102,204)">0</span><span class="" style="color:rgb(0,153,0)">)</span></div>

</li><li class="" style><div class="" style="padding:0px 5px;vertical-align:top;color:rgb(0,0,0);border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);background-color:rgb(255,255,255);line-height:21px">

        <span class="" style="color:rgb(177,177,0)">return</span> <span class="" style="color:rgb(0,153,0);font-weight:bold">FALSE</span><span class="" style="color:rgb(51,153,51)">;</span></div></li><li class="" style><div class="" style="padding:0px 5px;vertical-align:top;color:rgb(0,0,0);border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);background-color:rgb(255,255,255);line-height:21px">

    <span class="" style="color:rgb(177,177,0)">for</span> <span class="" style="color:rgb(0,153,0)">(</span><span class="" style="color:rgb(0,0,136)">$i</span> <span class="" style="color:rgb(51,153,51)">=</span> <span class="" style="color:rgb(204,102,204)">0</span><span class="" style="color:rgb(51,153,51)">;</span> <span class="" style="color:rgb(0,0,136)">$i</span> <span class="" style="color:rgb(51,153,51)"><</span> <span class="" style="color:rgb(0,0,136)">$num_rows</span><span class="" style="color:rgb(51,153,51)">;</span> <span class="" style="color:rgb(0,0,136)">$i</span><span class="" style="color:rgb(51,153,51)">++</span><span class="" style="color:rgb(0,153,0)">)</span> <span class="" style="color:rgb(0,153,0)">{</span></div>

</li><li class="" style><div class="" style="padding:0px 5px;vertical-align:top;color:rgb(0,0,0);border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);background-color:rgb(255,255,255);line-height:21px">

        <span class="" style="color:rgb(0,0,136)">$id</span> <span class="" style="color:rgb(51,153,51)">=</span> <span class="" style="color:rgb(0,0,136)">$adb</span><span class="" style="color:rgb(51,153,51)">-></span><span class="" style="color:rgb(0,64,0)">query_result</span><span class="" style="color:rgb(0,153,0)">(</span><span class="" style="color:rgb(0,0,136)">$result</span><span class="" style="color:rgb(51,153,51)">,</span> <span class="" style="color:rgb(0,0,136)">$i</span><span class="" style="color:rgb(51,153,51)">,</span> <span class="" style="color:rgb(0,0,255)">'id'</span><span class="" style="color:rgb(0,153,0)">)</span><span class="" style="color:rgb(51,153,51)">;</span></div>

</li><li class="" style><div class="" style="padding:0px 5px;vertical-align:top;color:rgb(0,0,0);border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);background-color:rgb(255,255,255);line-height:21px">

        <span class="" style="color:rgb(177,177,0)">if</span> <span class="" style="color:rgb(0,153,0)">(</span><span class="" style="color:rgb(51,153,51)">!</span><span class="" style="color:rgb(153,0,0)">in_array</span><span class="" style="color:rgb(0,153,0)">(</span><span class="" style="color:rgb(0,0,136)">$id</span><span class="" style="color:rgb(51,153,51)">,</span> <span class="" style="color:rgb(0,0,136)">$acc</span><span class="" style="color:rgb(0,153,0)">)</span><span class="" style="color:rgb(0,153,0)">)</span> <span class="" style="color:rgb(0,153,0)">{</span></div>

</li><li class="" style><div class="" style="padding:0px 5px;vertical-align:top;color:rgb(0,0,0);border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);background-color:rgb(255,255,255);line-height:21px">

            <span class="" style="color:rgb(153,0,0)">array_push</span><span class="" style="color:rgb(0,153,0)">(</span><span class="" style="color:rgb(0,0,136)">$acc</span><span class="" style="color:rgb(51,153,51)">,</span> <span class="" style="color:rgb(0,0,136)">$id</span><span class="" style="color:rgb(0,153,0)">)</span><span class="" style="color:rgb(51,153,51)">;</span></div>

</li><li class="" style><div class="" style="padding:0px 5px;vertical-align:top;color:rgb(0,0,0);border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);background-color:rgb(255,255,255);line-height:21px">

            getReportingUsers<span class="" style="color:rgb(0,153,0)">(</span><span class="" style="color:rgb(0,0,136)">$id</span><span class="" style="color:rgb(51,153,51)">,</span> <span class="" style="color:rgb(0,0,136)">$acc</span><span class="" style="color:rgb(0,153,0)">)</span><span class="" style="color:rgb(51,153,51)">;</span></div>

</li><li class="" style><div class="" style="padding:0px 5px;vertical-align:top;color:rgb(0,0,0);border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);background-color:rgb(255,255,255);line-height:21px">

        <span class="" style="color:rgb(0,153,0)">}</span></div></li><li class="" style><div class="" style="padding:0px 5px;vertical-align:top;color:rgb(0,0,0);border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);background-color:rgb(255,255,255);line-height:21px">

    <span class="" style="color:rgb(0,153,0)">}</span></div></li><li class="" style><div class="" style="padding:0px 5px;vertical-align:top;color:rgb(0,0,0);border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);background-color:rgb(255,255,255);line-height:21px">

<span class="" style="color:rgb(0,153,0)">}</span></div></li></ol></div><div style><br></div><div style>And</div><div style><br></div><div style><ol style="margin:0px;padding:0px 0px 0px 48px;color:rgb(172,172,172);font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono',monospace,serif;font-size:12px;line-height:21px;background-color:rgb(248,248,248)">

<li class="" style><div class="" style="padding:0px 5px;vertical-align:top;color:rgb(0,0,0);border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);background-color:rgb(255,255,255);line-height:21px">

<span class="" style="color:rgb(102,102,102);font-style:italic">//Checking if the Record Owner is a reporting User</span></div></li><li class="" style><div class="" style="padding:0px 5px;vertical-align:top;color:rgb(0,0,0);border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);background-color:rgb(255,255,255);line-height:21px">

<span class="" style="color:rgb(0,0,136)">$userids</span> <span class="" style="color:rgb(51,153,51)">=</span> <span class="" style="color:rgb(153,0,0)">array</span><span class="" style="color:rgb(0,153,0)">(</span><span class="" style="color:rgb(0,153,0)">)</span><span class="" style="color:rgb(51,153,51)">;</span></div>

</li><li class="" style><div class="" style="padding:0px 5px;vertical-align:top;color:rgb(0,0,0);border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);background-color:rgb(255,255,255);line-height:21px">

getReportingUsers<span class="" style="color:rgb(0,153,0)">(</span><span class="" style="color:rgb(0,0,136)">$current_user</span><span class="" style="color:rgb(51,153,51)">-></span><span class="" style="color:rgb(0,64,0)">id</span><span class="" style="color:rgb(51,153,51)">,</span><span class="" style="color:rgb(0,0,136)">$userids</span><span class="" style="color:rgb(0,153,0)">)</span><span class="" style="color:rgb(51,153,51)">;</span></div>

</li><li class="" style><div class="" style="padding:0px 5px;vertical-align:top;color:rgb(0,0,0);border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);background-color:rgb(255,255,255);line-height:21px">

<span class="" style="color:rgb(177,177,0)">if</span><span class="" style="color:rgb(0,153,0)">(</span><span class="" style="color:rgb(153,0,0)">in_array</span><span class="" style="color:rgb(0,153,0)">(</span><span class="" style="color:rgb(0,0,136)">$recOwnId</span><span class="" style="color:rgb(51,153,51)">,</span> <span class="" style="color:rgb(0,0,136)">$userids</span><span class="" style="color:rgb(0,153,0)">)</span><span class="" style="color:rgb(0,153,0)">)</span><span class="" style="color:rgb(0,153,0)">{</span></div>

</li><li class="" style><div class="" style="padding:0px 5px;vertical-align:top;color:rgb(0,0,0);border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);background-color:rgb(255,255,255);line-height:21px">

        <span class="" style="color:rgb(0,0,136)">$permission</span><span class="" style="color:rgb(51,153,51)">=</span><span class="" style="color:rgb(0,0,255)">'yes'</span><span class="" style="color:rgb(51,153,51)">;</span></div>

</li><li class="" style><div class="" style="padding:0px 5px;vertical-align:top;color:rgb(0,0,0);border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);background-color:rgb(255,255,255);line-height:21px">

        <span class="" style="color:rgb(0,0,136)">$log</span><span class="" style="color:rgb(51,153,51)">-></span><span class="" style="color:rgb(0,64,0)">debug</span><span class="" style="color:rgb(0,153,0)">(</span><span class="" style="color:rgb(0,0,255)">"Exiting isPermitted method ..."</span><span class="" style="color:rgb(0,153,0)">)</span><span class="" style="color:rgb(51,153,51)">;</span></div>

</li><li class="" style><div class="" style="padding:0px 5px;vertical-align:top;color:rgb(0,0,0);border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);background-color:rgb(255,255,255);line-height:21px">

        <span class="" style="color:rgb(177,177,0)">return</span> <span class="" style="color:rgb(0,0,136)">$permission</span><span class="" style="color:rgb(51,153,51)">;</span></div></li><li class="" style><div class="" style="padding:0px 5px;vertical-align:top;color:rgb(0,0,0);border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);background-color:rgb(255,255,255);line-height:21px">

<span class="" style="color:rgb(0,153,0)">}</span></div></li></ol></div><div style><br></div><div style>And the log <a href="http://pastebin.com/LwDmj8M5">http://pastebin.com/LwDmj8M5</a></div><div style><br></div><div style>

Please let me know your opinion about this.</div><div style><br></div><div style>Thanks</div><div style>--</div><div style>Salim</div><div style><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On 30 April 2013 21:38, Adam Heinz <span dir="ltr"><<a href="mailto:amh@metricwise.net" target="_blank">amh@metricwise.net</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Users always find a way to get bad data into the system.  ;)  I have added a ton of referential integrity to our fork of vtiger and crap still makes it in periodically.<div>

<br></div><div>Check out this tutorial [3] on tail recursion and accumulators.  Basically you'll just accumulate an array of userids and use in_array to make sure that you don't process the same userid twice.  PHP doesn't optimize for tail recursion, so I would recommend writing it as a loop inside a function.</div>


<div><br></div><div>[3] <a href="http://siddhi.blogspot.com/2006/04/recursion-part-2-tail-recursion.html" target="_blank">http://siddhi.blogspot.com/2006/04/recursion-part-2-tail-recursion.html</a><br></div></div><div class="gmail_extra">


<br><br><div class="gmail_quote"><div><div class="h5">On Tue, Apr 30, 2013 at 11:40 AM, salim <span dir="ltr"><<a href="mailto:salimcmd@gmail.com" target="_blank">salimcmd@gmail.com</a>></span> wrote:<br></div></div>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5">
<div dir="ltr">Adam,<br>    You saying that make two users to report to each other, like  <b>UserA </b>---> <b>UserB</b> , <b>UserB ---> UserA</b>. Will it happen in real scenario?
<div>If so this will happen <a href="http://pastebin.com/jrFmBnxS" target="_blank">http://pastebin.com/jrFmBnxS</a>. It dropped in a infinite loop.  :P</div><div><br></div><div>How you proposing accumulator in Recursive function.</div>




<div><br></div><div>Thanks</div><div>--</div><div>Salim</div></div><div class="gmail_extra"><br><br><div class="gmail_quote"><div><div>On 30 April 2013 20:14, Adam Heinz <span dir="ltr"><<a href="mailto:amh@metricwise.net" target="_blank">amh@metricwise.net</a>></span> wrote:<br>




</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><div dir="ltr">Ooooooh, reverse that again, it could be cyclic, even though that would make so sense, the system does not enforce it.  Definitely need the accumulator to avoid an infinite loop.  Set two users to report to each other and see if it explodes.  ;)</div>




<div><div>
<div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Apr 30, 2013 at 10:14 AM, Adam Heinz <span dir="ltr"><<a href="mailto:amh@metricwise.net" target="_blank">amh@metricwise.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">





<div dir="ltr"><div>On Tue, Apr 30, 2013 at 10:12 AM, Adam Heinz <span dir="ltr"><<a href="mailto:amh@metricwise.net" target="_blank">amh@metricwise.net</a>></span> wrote:<br></div><div class="gmail_extra">
<div class="gmail_quote"><div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">You should add some sort of accumulator to getReportingUsers so that you don't recur for userids you have already checked.</div>






</blockquote><div><br></div></div><div>Scratch this comment, we're walking a directed acyclic graph; redundancy is impossible.</div></div></div></div>
</blockquote></div><br></div>
</div></div><br></div></div>_______________________________________________<br>
<a href="http://www.vtiger.com/" target="_blank">http://www.vtiger.com/</a><span><font color="#888888"><br></font></span></blockquote></div><span><font color="#888888"><br><br clear="all"><div>
<br></div>-- <br>Muhammed Abdul Salim<br>
</font></span></div>
<br></div></div>_______________________________________________<br>
<a href="http://www.vtiger.com/" target="_blank">http://www.vtiger.com/</a><br></blockquote></div><br></div>
<br>_______________________________________________<br>
<a href="http://www.vtiger.com/" target="_blank">http://www.vtiger.com/</a><br></blockquote></div><br><br clear="all"><div><br></div>-- <br>Muhammed Abdul Salim<br>
</div>