troubleshooting Question

Php catch usage?

Avatar of lhaluska
lhaluska asked on
PHP
2 Comments1 Solution1230 ViewsLast Modified:
I am trying to write this catch try code but have know clue how to translate between cfm to php can someone help please. Here is the code in php.
<?php
$Bhupi = 'bsingh@cup.com';
$webmaster = '<a href="mailto:lhaluska@cup.com?subject=Service Request Error">lhaluska</a>(408)285-1596';
$Foobar = false;
$SRDATESTAMP = date("MMMM D, YYYY");
$SRTIMESTAMP = time("hh:mm");
$SRDATETIMESTAMP = &$SRDATESTAMP &$SRTIMESTAMP;
$Foobar = false;
$auth = $_SERVER['AUTH_USER'];
$ntUserDomainId = str_replace('\\',':','$auth');
$Identified = false;
if ($Identified == 'false') {
try {
$ds=ldap_connect("ldap.cce.cup.com:389");
$r=ldap_bind($ds);
$sr=ldap_search($ds, "o=cup.com", 'uid='.$ntUserDomainId, explode(',', 'sn,givenname,telephonenumber,manager,ntUserDomainId,cupJobTitle,ou,uid,EMPLOYEENUMBER,managerEMPLOYEENUMBER,cn,mailRoutingAddress'));
$info = ldap_get_entries($ds, $sr);
catch (Exception $e)
{ echo 'Caught exception: ',  $e->getMessage(), "\n";
try {
$ds=ldap_connect("ldap.cup.com:389");
$r=ldap_bind($ds);
$sr=ldap_search($ds, "o=cup.com", 'uid='.$ntUserDomainId, explode(',', 'sn,givenname,telephonenumber,manager,ntUserDomainId,cupJobTitle,ou,uid,EMPLOYEENUMBER,managerEMPLOYEENUMBER,cn,mailRoutingAddress'));
$info = ldap_get_entries($ds, $sr);
}
}
?>

Here is the cfm code I am changing..
<cfset Bhupi = "bsingh@cup.com">

<!--- Need a var to break the loop. --->
<cfset Foobar = false>
            <cflock scope="server" type="readonly" timeout="3">
                  <cfset ntUserDomainId = "#Replace("#AUTH_USER#","\",":")#">
            </cflock>            
<cfset Identified = false>
<cflock scope="session" type="readonly" timeout="5">
      <cfif IsDefined("session.routeTo") AND Len("session.routeTo") GT 0>
            <cfset Identified = true>
      </cfif>
</cflock>

<cfif Identified is false>
      <cftry>
            <cfldap action="QUERY"
                              name="UserData"
                  attributes="sn,givenname,telephonenumber,manager,ntUserDomainId,cupJobTitle,ou,uid,EMPLOYEENUMBER,managerEMPLOYEENUMBER,cn,mailRoutingAddress"
                              start="o=cup.com"
                              scope="SUBTREE"
                              filter="ntUserDomainId=#ntUserDomainId#"
                              server="ldap.cce.cup.com"
                              port="389">
            <cfcatch>
                  <cftry>
                        <cfldap action="QUERY"
                                    name="UserData"
                        attributes="sn,givenname,telephonenumber,manager,ntUserDomainId,cupJobTitle,ou,uid,EMPLOYEENUMBER,managerEMPLOYEENUMBER,cn,mailRoutingAddress"
                                    start="o=cup.com"
                                    scope="SUBTREE"
                                    filter="ntUserDomainId=#ntUserDomainId#"
                                    server="ldap.cup.com"
                                    port="389">
                  <cfcatch>
                        <cfoutput>#cfcatch.Detail#  #cfcatch.Message# <br></cfoutput>
                        <cfmail from="lssstools@cup.com"
                                    to="lhaluska@cup.com"
                                    cc="lhaluska@cup.com"
                                    subject="LDAP Error on SR">
                                    #cfcatch.Detail#<br>
                                    #cfcatch.Message#<br>
                                    #ntUserDomainId#<br>
                                    #SRDATETIMESTAMP#
                        </cfmail>
                        <cfoutput>The Webmaster has been automatically notified. If you wish to add info, please do so:<br>            
                        <a href="mailto:lhaluska@cup.com?subject=LDAP error on SR">Notify Webmaster.</a></cfoutput>
                        <cfabort>
                  </cfcatch>
                  </cftry>
            </cfcatch>
            </cftry>
            <cfcookie name="EMAIL" value="#UserData.uid#" expires="30">
            <cfcookie name="PHONE" value="#UserData.telephonenumber#" expires="30">
            <cfset user = "#LCase("#ListLast("#ListFirst("#UserData.uid#")#","=")#")#">
            <cfif user IS NOT #Bhupi# AND Foobar IS false>
            <cfset user = "#LCase("#ListLast("#ListFirst("#userData.manager#")#","=")#")#">
            <cfset loopcounter = 0>
            <cfloop condition="user IS NOT #Bhupi# AND Foobar IS false">
            <cftry>
                  <cfldap action="QUERY"
                                    name="UserData2"
                        attributes="sn,givenname,telephonenumber,manager,ntUserDomainId,cupJobTitle,ou,uid,EMPLOYEENUMBER,managerEMPLOYEENUMBER,cn,mailRoutingAddress"
                                    start="o=cup.com"
                                    scope="SUBTREE"
                                    filter="uid=#user#"
                                    server="ldap.cce.cup.com"
                                    port="389">
            <cfcatch>
                  <cftry>
                        <cfldap action="QUERY"
                                    name="UserData2"
                        attributes="sn,givenname,telephonenumber,manager,ntUserDomainId,cupJobTitle,ou,uid,EMPLOYEENUMBER,managerEMPLOYEENUMBER,cn,mailRoutingAddress"
                                    start="o=cup.com"
                                    scope="SUBTREE"
                                    filter="uid=#user#"
                                    server="ldap.cup.com"
                                    port="389">
                  <cfcatch>
                        <cfoutput>#cfcatch.Detail#  #cfcatch.Message# <br></cfoutput>
                        <cfmail from="lssstools@cup.com"
                                    to="lhaluska@cup.com"
                                    subject="LDAP Error on SR">
                                    #ntUserDomainId#<br>
                                    #SRDATETIMESTAMP#<br>
                                    #user#<br>
                                    #cfcatch.Detail#<br>
                                    #cfcatch.Message#<br>
                        </cfmail>
                        <cfoutput>The Webmaster has been automatically notified. If you wish to add info, please do so:<br>            
                        <a href="mailto:lhaluska@cup.com?subject=LDAP error on SR">Notify Webmaster.</a></cfoutput>
                        <cfabort>
                  </cfcatch>
                  </cftry>
            </cfcatch>
            </cftry>
                  <cfset user = "#LCase("#ListLast("#ListFirst("#UserData2.manager#")#","=")#")#">
                  <cfset loopcounter = #loopcounter# + 1>
                  <cfif loopcounter GTE 7>
                        <cfset Foobar = true>
                  </cfif>
            </cfloop>
      </cfif>
      <cfif user IS Bhupi>
            <cflock timeout="1" type="exclusive" scope="session">
                  <cfset session.routeTo = "5996">
            </cflock>
      <cfelse>
            <cflock timeout="1" type="exclusive" scope="session">
                  <cfset session.routeTo = "9999">
            </cflock>
      </cfif>
</cfif>
<cfset webmaster = '<a href="mailto:LHaluska@cup.com?subject=service request error">LHaluska</A> (888) 888-1234'>
<cfset SRDATESTAMP = #DateFormat("#now()#", "mmmm d, yyyy")#>
<cfset SRTIMESTAMP = #TimeFormat(Now(), 'HH:mm')#>      
<cfset SRDATETIMESTAMP = "#SRDATESTAMP# #SRTIMESTAMP#">
ASKER CERTIFIED SOLUTION
Stacy Spear
President/Principal Consultant

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros